-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathCurryExample.js
More file actions
60 lines (34 loc) · 906 Bytes
/
CurryExample.js
File metadata and controls
60 lines (34 loc) · 906 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// what is currying in javascript
// sumCurry(1)(2)(4) // => 1+2+4 => 7
const sumCurry =(a)=>{
return (b)=>{
return (c)=>{
return a+b+c;
}
}
}
const data = sumCurry(4);
const data1 = data(5);
// const curry = sumCurry(100)(40)(30);
// console.log(curry)
// infinite currying
//
const infiniteCurrySum = (a)=>{
return (b)=> {
if(!b){
return a
}else {
return infiniteCurrySum(a+b);
}
}
}
const check = infiniteCurrySum(1)(2)(3)(4)(5)(6)(7)(n)();
// const mul = (a,b,c) => {
// return a*b*c;
// }
// const curried = advancedCurry(mul);
// curried(1,2,3) // => 6
// curried(1)(2,3) // => 6
// curried(1)(2)(3); // =>
//call(a,b,c) => call(a)(b)(c) => closure
// what is the disadvantage of the closure => extraa memory because due closue variable are not garb age collected