-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurrying.js
More file actions
43 lines (39 loc) · 782 Bytes
/
currying.js
File metadata and controls
43 lines (39 loc) · 782 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
// function curryN(fn, n) {
// if(typeof n !== 'number') n = fn.length;
//
// function genCurry(prev) {
// return function(arg) {
// let args = prev.concat(arg);
// if(args.length < n) return genCurry(args);
// return fn.apply(this, args);
//
//
// };
// }
//
// return genCurry([]);
//
//
// }
//
// module.exports = curryN;
function curryN(fn, n){
if(typeof n!= 'number')
n = fn.length;
function abc(pre){
return function(arg) {
pre.push(arg);
if(pre.length < n)
return abc(pre);
//console.log('end pre=', pre);
return fn(pre);
};
}
return abc([]);
}
module.exports = curryN;
function fn(arr)
{
//console.log('inside fn arr=',arr);
return arr.reduce((pre,current) => pre+current, 0);
}