Description

Currying is a way to transform a function so that it can be called one argument at a time.

In this challenge, you will implement a simple version of currying for a function that always takes exactly 3 arguments.


The curried version should be called like this:


curriedFn(a)(b)(c)


This is a great exercise to understand how arguments can be collected and passed step by step.

Your Task

Write a function curry(fn) that takes a function fn(a, b, c) and returns a curried version.

The curried function will be called exactly 3 times, each time with one argument, and finally return the result of fn.

Example

Input

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

const curriedAdd = curry(add);

console.log(curriedAdd(1)(2)(3));

Expected Output

6

Explanation

  • curriedAdd(1) returns a function waiting for the next argument.
  • curriedAdd(1)(2) returns another function waiting for the third argument.
  • curriedAdd(1)(2)(3) finally calls add(1, 2, 3) and returns the result 6.