Skip to content

Instantly share code, notes, and snippets.

@usametov
Created April 1, 2018 14:40
Show Gist options
  • Save usametov/0652f1863dea84b7aa99b4490f6d9036 to your computer and use it in GitHub Desktop.
Save usametov/0652f1863dea84b7aa99b4490f6d9036 to your computer and use it in GitHub Desktop.
ES6 pattern matching using destructuring
const map = (f, [x, ...xs]) => (
(x === undefined && xs.length === 0) ? []
: [f(x), ...map(f, xs)]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment