Created
March 28, 2017 17:49
-
-
Save ccorcos/e61ae52f7b480a219e3e861d52f8c4d8 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
let rec firstN n l => | |
if (n === 0 || List.length l === 0) { | |
[] | |
} else { | |
let h = List.hd l; | |
let t = List.tl l; | |
List.append [h] (firstN (n - 1) t) | |
}; | |
firstN 2 [1, 2, 3, 4, 5]; /* => list int: [1, 2] */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment