Last active
March 4, 2017 09:54
-
-
Save 50kudos/5d21d53f2f6d975ce8f80c6e00c50131 to your computer and use it in GitHub Desktop.
This file contains 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(w22list). | |
-export([take/2, nub/1]). | |
-spec take(integer(), [T]) -> T. | |
take(0, _L) -> []; | |
take(I, L) when I < 0 orelse I > length(L) -> L; | |
take(I, [H|T]) -> | |
[H | take(I-1, T)]. | |
nub(L) -> nub(lists:sort(L), []). | |
nub([H|[]], ACC) -> lists:reverse([H | ACC]); | |
nub([H|T], ACC) -> | |
case hd(T) of | |
H -> nub(T, ACC); | |
_ -> nub(T, [H | ACC]) | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[H|[]]
could be written as[H]
But your code changes the order of elements.