Implement Pipe
EasyFunctional Programming10 min4 tests
Implement a pipe function that takes multiple functions and returns a new function that applies them left-to-right (the opposite of compose).
Requirements
pipe(f, g, h)(x)should equalh(g(f(x)))- Should work with any number of functions
Example
const add1 = x => x + 1;
const double = x => x * 2;
pipe(add1, double)(5); // 12 (add1 first: 6, then double: 12)Hints (2)
- Very similar to compose but in the opposite direction.
- Use
reduceinstead ofreduceRight.
Topics
- Functional Programming
Asked at
Stripe · Airbnb
