-
Notifications
You must be signed in to change notification settings - Fork 0
/
currying.js
41 lines (41 loc) · 971 Bytes
/
currying.js
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
var cost = (function () {
var args = [];
return function () {
if (arguments.length == 0) {
var money = 0;
for (var i = 0; i < args.length; i++) {
money += args[i];
}
return money;
} else {
[].push.apply(args, arguments);
console.log(args);
}
}
})();
var currying = function (fn) {
var args = [];
return function result() {
if(arguments.length===0){
return fn.apply(this,args);
}else {
[].push.apply(args,arguments);
console.log(args);
return result;
}
}
};
var cost1 = (function () {
var money = 0;
return function () {
for (var i = 0; i < arguments.length; i++) {
money += arguments[i];
}
return money;
}
})();
cost1 = currying(cost1);
cost1(100,200,300)(400,600);
cost1(400,500);
cost1(600);
console.log(cost1());