Explorer
Node.js

Write a `compose(...fns)` that composes functions right-to-left. `compose(f, g)(x)` should equal `f(g(x))`.

Problem Statement

Write a `compose(...fns)` that composes functions right-to-left. `compose(f, g)(x)` should equal `f(g(x))`.

Complexity

Time Complexity: -

Space Complexity: -

Hints

šŸ’” Hint 1: Function composition applies functions in sequence. šŸ’” Hint 2: Use reduceRight to apply functions from right to left. šŸ’” Hint 3: return (x) => fns.reduceRight((acc, fn) => fn(acc), x); āœ… Solution: ```javascript function compose(...fns) { return (x) => fns.reduceRight((acc, fn) => fn(acc), x); } ```

Compose Functions

Medium
Write a `compose(...fns)` that composes functions right-to-left. `compose(f, g)(x)` should equal `f(g(x))`.
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
12