const compose = (...fns) => x => fns.reduceRight((acc, fn) => fn(acc), x);
const pipe = (...fns) => x => fns.reduce((acc, fn) => fn(acc), x);
const inc = x => x + 1;
const double = x => x * 2;
const square = x => x * x;
const f = compose(square, double, inc);
const g = pipe(square, double, inc);
console.log(f(2), g(2));
Post #3461
2.12K
CHALLENGE
- 👍 4
- 🔥 2
- ❤ 1