-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4_currying.js
More file actions
32 lines (24 loc) · 846 Bytes
/
4_currying.js
File metadata and controls
32 lines (24 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(
function () {
/*
What is Currying?
ans. When a function doesn't take all required arguments at one call
but instead it returns function that takes argument
then it's called currying.
*/
/* old syntax */
function simple_interest1(principal){
return function(time){
return function(rate){
return principal/100 * time * rate;
}
}
}
/* new syntax */
var simple_interest = principal => time => rate => principal/100 * time * rate;
console.log(simple_interest(1000)(1)(20))
/*
Did you notice that currying is only possible because of closures in the upper case?
*/
}
)();