Skip to content

Instantly share code, notes, and snippets.

@lilywang711
Created September 12, 2020 12:11
Show Gist options
  • Save lilywang711/b4fcc260646dc7b76e7b4ebac9046987 to your computer and use it in GitHub Desktop.
Save lilywang711/b4fcc260646dc7b76e7b4ebac9046987 to your computer and use it in GitHub Desktop.
const compose = (...fns) => (input) => fns.reverse().reduce((acc, fn) => fn(acc), input);
const addOne = (x) => x + 1;
const square = (x) => x * x;
console.log(compose(addOne, square)(2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment