Skip to content

Instantly share code, notes, and snippets.

@HugoDF
Last active October 14, 2016 14:22
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/98fbeb99d3ed3cc771e8ba7ad664f909 to your computer and use it in GitHub Desktop.
Save HugoDF/98fbeb99d3ed3cc771e8ba7ad664f909 to your computer and use it in GitHub Desktop.
ES6 filter implementation using recursion and destructuring
function filter([ head, ...tail ], fn) {
const newHead = fn(head) ? [ head ] : [];
return tail.length ? [ ...newHead, ...(filter(tail, fn)) ] : newHead;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment