2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
29
Task/Currying/JavaScript/currying-11.js
Normal file
29
Task/Currying/JavaScript/currying-11.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
(() => {
|
||||
|
||||
// (arbitrary arity to fully curried)
|
||||
// extraCurry :: Function -> Function
|
||||
let extraCurry = (f, ...args) => {
|
||||
let intArgs = f.length;
|
||||
|
||||
// Recursive currying
|
||||
let _curry = (xs, ...arguments) =>
|
||||
xs.length >= intArgs ? (
|
||||
f.apply(null, xs)
|
||||
) : function () {
|
||||
return _curry(xs.concat([].slice.apply(arguments)));
|
||||
};
|
||||
|
||||
return _curry([].slice.call(args, 1));
|
||||
};
|
||||
|
||||
// TEST
|
||||
|
||||
// product3:: Num -> Num -> Num -> Num
|
||||
let product3 = (a, b, c) => a * b * c;
|
||||
|
||||
return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
.map(extraCurry(product3)(7)(2))
|
||||
|
||||
// [14, 28, 42, 56, 70, 84, 98, 112, 126, 140]
|
||||
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue