Skip to content

Commit

Permalink
added a interview question on currying concept (sumn2u#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
IndraniSom authored Oct 27, 2023
1 parent 9efcc1b commit ac17cb5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions en/interview-questions/intermediate-level.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,23 @@ You can use the test() method of regular expression in order to search a string
var pattern = /you/;
console.log(pattern.test("How are you?")); //true
```
### 6.7. What is Currying in Javascript?

**Answer:**

Currying in JavaScript transforms a function with multiple arguments into a nested series of functions, each taking a single argument. Currying helps you avoid passing the same variable multiple times, and it helps you create a higher order function.
That is, when we turn a function call sum(1,2,3) into sum(1)(2)(3).

The number of arguments a function takes is also called arity.

```
function sum(a, b) {
// do something
}
function _sum(a, b, c) {
// do something
}
```
The function sum takes two arguments (two-arity function) and _sum takes three arguments (three-arity function).

Curried functions are constructed by chaining closures and by defining and immediately returning their inner functions simultaneously.

0 comments on commit ac17cb5

Please sign in to comment.