Skip to content

Instantly share code, notes, and snippets.

@gorkaio
Created May 8, 2020 15:30
Show Gist options
  • Save gorkaio/f23ee12af81e910c1c2e3b0cdb43b13f to your computer and use it in GitHub Desktop.
Save gorkaio/f23ee12af81e910c1c2e3b0cdb43b13f to your computer and use it in GitHub Desktop.
-module(nub).
-export([nub/1]).
-export([nub_test/0]).
nub([]) -> [];
nub([_|_] = L) -> nub(L, []).
nub([], Ac) -> lists:reverse(Ac);
nub([H|T], Ac) ->
case lists:member(H, Ac) of
true -> nub(T, Ac);
false -> nub(T, [H|Ac])
end.
nub_test() ->
[] = nub([]),
[1] = nub([1]),
[1] = nub([1,1,1,1]),
[1,2] = nub([1,2]),
[1,-2,2,0.5,'a'] = nub([1,-2,2,1,0.5,'a',2]),
"led zpin" = nub("led zeppelin"),
passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment