JS Built-ins
FunctionalProgrammingintermediate

Pipe three functions

πŸ“– Usage Example
const pipe = (...fns) => x => fns.reduce((v, f) => f(v), x);
const trim = s => s.trim();
const toLower = s => s.toLowerCase();
const process = pipe(trim, toLower);
process('  Hello  '); // 'hello'

Pipe functions to build a clean data-transformation pipeline.

Multi-function Pipeline

Chain three functions together using pipe.

Challenge: Use pipe to compose three functions: add2(x), square(x), and subtract10(x) in that order.

πŸ’‘ Hints (3)
  • β€’ Add 2, then square, then subtract 10
  • β€’ Order is left-to-right
  • β€’ Each output becomes the next input