# How to uncurry a function up to depth n in JavaScript ?

• Last Updated : 02 Jul, 2021

The following approach covers how to uncurry a function up to depth n in JavaScript. Uncurry a function is a process of wrapping function arguments and pass all the arguments at once. Uncurry up-to depth n means we have passed only n arguments in all arguments.

This can be done by following methods:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

• Using reduce() Method
• Using for-of loop Method

Using reduce() Method:Reduce method is used to apply an operation on all the elements of the list and returns the result. It takes a callback that applies to all the elements. To slice args up to n we use the slice() method. The slice() method extracts part of the elements from the list. The slice() takes starting index and end index up to what we want to extract. Starting index is by default 0 if not provide any args. End index we can provide up to the end of the list.

Example:

## Javascript

 ``

Output:

`Sum of 3 args are 7`

Using or-of loop Method: In this method, we use for-of loop. The for-of loop is used to iterate over all the elements of the list. Following are implementation of the method:

• Define n and sum function that add all provided arguments.
• Call uncurrry function with the sum, n, and all list of numbers.
• The uncurry function checks if n is greater than arguments then returns fewer args provide.
• Else it iterates the overall argument and applies function sum to each argument.
• In for loop, we count iteration. When iteration becomes equal to n break the loop.
• At the end returns f which sum of all passed elements.

Example:

## Javascript

 ``

Output:

`Sum of 3 args is 8`

My Personal Notes arrow_drop_up