Created
June 28, 2017 08:51
-
-
Save i7an/8de54678f5b75400a510a25e5c0dcae7 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(main). | |
-export([take/2, take_test/0]). | |
-spec take(integer(), [T]) -> [T]. | |
take(N, List) when N >= 0 -> take(N, List, []). | |
take(0, _List, Acc) -> Acc; | |
take(_N, [], Acc) -> Acc; | |
take(N, [X|Xs], Acc) -> take(N-1, Xs, Acc ++ [X]). | |
take_test() -> | |
[] = take(0, [1]), | |
[] = take(1, []), | |
[1,2] = take(2, [1,2,3]), | |
ok. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment