Last active
October 18, 2016 19:00
-
-
Save HugoDF/198c2fef377e69b88696e6e10f15d1ae to your computer and use it in GitHub Desktop.
ES6 map implementation using recursion and destructuring
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
function map([ head, ...tail ], fn) { | |
if (head === undefined && !tail.length) return []; | |
return tail.length ? [ fn(head), ...(map(tail, fn)) ] : [ fn(head) ]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment