Guest User

Untitled

a guest
Sep 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. function fun(f) {
  2. return function curry() {
  3. if (arguments.length < f.length) {
  4. var args = Array.prototype.slice.call(arguments);
  5. return function () {
  6. return curry.apply(this, args.concat(Array.prototype.slice.call(arguments)));
  7. }
  8. } else {
  9. return f.apply(this, arguments);
  10. }
  11. }
  12. }
  13.  
  14. var add = fun(function (a, b, c) {
  15. return a + b + c;
  16. });
  17.  
  18. console.log(add(1, 2, 3)); // 6
  19. console.log(add(1)(2, 3)); // 6
  20. console.log(add(1)(2)(3)); // 6
  21. console.log(add(1, 2)(3)); // 6
Add Comment
Please, Sign In to add comment