MediumPro challengePythonJavaScriptTypeScript

Curry

FunctionsClosuresPatterns

Implement curry(fn) that returns a curried version of fn. The curried
function collects arguments one at a time and calls fn once it has
received all of them.

solve(ops) drives your implementation where each op is 'call' (partial
apply one more arg) or 'exec' (get accumulated result).

Example — currying an add3 function

const add3 = curry((a, b, c) => a + b + c);
add3(1)(2)(3)  // 6
add3(1, 2)(3)  // 6
add3(1)(2, 3)  // 6

Sample tests

Test #1One arg per call: (1)(2)(3)
Input: [[[1],[2],[3]]]
Output: 6
Test #2Two args first, then one: (1,2)(3)
Input: [[[1,2],[3]]]
Output: 6
Test #3All args at once: (1,2,3)
Input: [[[1,2,3]]]
Output: 6
Test #4All zeros
Input: [[[0],[0],[0]]]
Output: 0
Test #5(10,20)(30)
Input: [[[10,20],[30]]]
Output: 60