Skip to content
Junior–Senior166 views

Flexible function currying with an arbitrary number of calls

Task condition

You need to write a curry function that allows partial invocation of a given function, passing arguments gradually through a chain of calls. The function should remember the received arguments and, once their number reaches the number of parameters of the original function, execute it and return the result.

function sum(a, b, c, d) {
    return a + b + c + d;
}

const curriedSum = curry(sum);

console.log(curriedSum(1)(2)(3)(4));       // 10
console.log(curriedSum(1, 2)(3)(4));       // 10
console.log(curriedSum(1)(2, 3, 4));       // 10
Frontend tasks in the code trainer