JS Built-ins
FunctionalProgrammingintermediate

Compose β€” right-to-left composition

πŸ“– Usage Example
const compose = (...fns) => x => fns.reduceRight((v, f) => f(v), x);
const double = x => x * 2;
const add1 = x => x + 1;
const process = compose(add1, double);
process(3); // double runs first: 3*2+1 = 7

compose() applies functions right-to-left β€” mathematical composition order.

Compose Function

A compose function is the traditional approach, applying functions right-to-left (mathematical notation).

Challenge: Implement a compose utility that takes multiple functions and returns a new function applying them right-to-left.

πŸ’‘ Hints (3)
  • β€’ Use reduceRight to reverse order
  • β€’ reduceRight processes from right to left
  • β€’ Same as mathematical function composition