FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Medium

Curry II

25mins

Implement a function curry(fn) that transforms a function which takes multiple arguments into a function that can be repeatedly called with any number of arguments until all arguments are provided.

The function should:

  • Collect arguments from multiple calls.
  • Return the final result when the total number of arguments meets the original function's arity.
  • Support any number of arguments per call.

Example

function sum(a, b, c) { return a + b + c; } const curried = curry(sum); curried(1)(2)(3); // 6 curried(1, 2)(3); // 6 curried(1)(2, 3); // 6

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests