Skip to content

Instantly share code, notes, and snippets.

@dewey92
Created April 18, 2017 14:23
Show Gist options
  • Save dewey92/7abb861ba27fb2d47a0674bb7d91146d to your computer and use it in GitHub Desktop.
Save dewey92/7abb861ba27fb2d47a0674bb7d91146d to your computer and use it in GitHub Desktop.
const filter = (fn, arr) => {
const [head, ...tail] = arr
if (tail[0] === undefined) return []
if (fn(head)) {
return [head, ...filter(fn, tail)]
} else {
return [...filter(fn, tail)]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment