Problem, as an interviewer would state it:
"Implement curry(fn) — returning a version of fn that can genuinely be called with arguments split across ANY number of separate calls, only actually invoking the original function once ENOUGH total arguments have been collected."
Examples:
const curried = curry((a,b,c) => a+b+c);
curried(1)(2)(3); // 6
curried(1,2,3); // 6
curried(1,2)(3); // 6
Clarifying questions expected:
- How does this determine "enough" arguments have been collected — via the function's own declared arity (
fn.length)? - Does a partially-applied intermediate function need to be genuinely REUSABLE for multiple different later completions?
- Should this work for a function of ANY arity, not just a fixed number of parameters?
Code / implementation expected: Yes — real, direct proof that all real call-pattern variations (fully split, fully combined, and every mix in between) produce the identical result, plus confirmation a partial application is genuinely reusable.