JS Built-ins
FunctionalProgrammingbeginner

Function composition β€” manual

πŸ“– Usage Example
const add1 = x => x + 1;
const double = x => x * 2;
const result = double(add1(3)); // 8

Function composition chains functions so the output of one feeds into the next.

Function Composition Basics

Function composition combines simple functions into more complex ones by nesting function calls.

Challenge: Given two functions add1(x) and double(x), compose them manually to create a function that adds 1 then doubles the result.

πŸ’‘ Hints (3)
  • β€’ Call the first function, pass its result to the second
  • β€’ Composition reads right-to-left (innermost first)
  • β€’ Order of function application matters