Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fun(f) {
- return function curry() {
- if (arguments.length < f.length) {
- var args = Array.prototype.slice.call(arguments);
- return function () {
- return curry.apply(this, args.concat(Array.prototype.slice.call(arguments)));
- }
- } else {
- return f.apply(this, arguments);
- }
- }
- }
- var add = fun(function (a, b, c) {
- return a + b + c;
- });
- console.log(add(1, 2, 3)); // 6
- console.log(add(1)(2, 3)); // 6
- console.log(add(1)(2)(3)); // 6
- console.log(add(1, 2)(3)); // 6
Add Comment
Please, Sign In to add comment