Skip to content

Commit ac17cb5

Browse files
authored
added a interview question on currying concept (#180)
1 parent 9efcc1b commit ac17cb5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

en/interview-questions/intermediate-level.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,23 @@ You can use the test() method of regular expression in order to search a string
317317
var pattern = /you/;
318318
console.log(pattern.test("How are you?")); //true
319319
```
320+
### 6.7. What is Currying in Javascript?
321+
322+
**Answer:**
323+
324+
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.
325+
That is, when we turn a function call sum(1,2,3) into sum(1)(2)(3).
326+
327+
The number of arguments a function takes is also called arity.
328+
329+
```
330+
function sum(a, b) {
331+
// do something
332+
}
333+
function _sum(a, b, c) {
334+
// do something
335+
}
336+
```
337+
The function sum takes two arguments (two-arity function) and _sum takes three arguments (three-arity function).
338+
339+
Curried functions are constructed by chaining closures and by defining and immediately returning their inner functions simultaneously.

0 commit comments

Comments
 (0)