Skip to content

Instantly share code, notes, and snippets.

@HugoDF
Last active October 18, 2016 19:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HugoDF/198c2fef377e69b88696e6e10f15d1ae to your computer and use it in GitHub Desktop.
Save HugoDF/198c2fef377e69b88696e6e10f15d1ae to your computer and use it in GitHub Desktop.
ES6 map implementation using recursion and destructuring
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