-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurrying.js
More file actions
54 lines (33 loc) · 935 Bytes
/
Copy pathCurrying.js
File metadata and controls
54 lines (33 loc) · 935 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
// Currying is javascript technique where a function take multiple arguments one at a time. It use because avoid repating code
// using bind method
let multiply = function(x, y){
return x*y;
}
let multipleByOne = multiply.bind(this);
console.log(multipleByOne(6,6));
let multipleByTwo = multiply.bind(this);
console.log(multipleByTwo(11,12));
// other way of using bind
let multiple = function(a,b){
console.log(a**b);
}
let multipleByX = multiple.bind(this);
multipleByX(2,3);
let multipleByY = multiple.bind(this);
multipleByY(12,3);
// Using function Closures
let Multiply = function(x){
return function(y){
console.log(x*y);
}
}
let MultiplyByOne = Multiply(6);
MultiplyByOne(3);
// Infinite Currying Question
function add(a){
return function(b){
if(b) return add(a+b);
return a;
}
}
console.log(add(2)(3)(4)(10)());