FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Easy

Compose

10mins

Implement a function compose(...fns) that takes multiple functions as arguments and returns a new function that applies those functions in reverse order (from right to left).

Examples

const add = x => x + 1; const double = x => x * 2; const fn = compose(add, double); fn(2); // double(2) = 4, add(4) = 5 const fn2 = compose(Math.sqrt, x => x + 1, x => x * 2); fn2(3); // ((3 * 2) + 1) = 7, sqrt(7) ≈ 2.6457513110645907

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests