Created
May 8, 2020 15:30
-
-
Save gorkaio/f23ee12af81e910c1c2e3b0cdb43b13f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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