Junior — Senior
Function composition through currying with an arbitrary number of arguments
livecode
Task condition
Implement a function compose that, using currying, accepts any number of functions and returns a new function. When this returned function is called, it should be passed an initial number – which will be fed into the first function, its result into the second, and so on until the last function is executed.
const a = (x) => x * 2;
const b = (x) => x * 2;
const c = (x) => x * 2;
// Expected result: a(b(c(2))) // 16
// compose(a, b, c)(2);
The function should work correctly with any number of functions (including one) and return the result of the last function in the chain.