stoyanmkd

JS - Function Recursion

Feb 8th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function add(a){
  2.     var sum = function(b){
  3.         return add(a + b);
  4.     };
  5.  
  6.     sum.valueOf = sum.toString = function() {
  7.         return a;
  8.     };
  9.  
  10.     return sum;
  11. }
  12.  
  13. console.log(add(1));
  14. console.log(add(2)(3));
  15. console.log(add(1)(1)(1)(1)(1));
  16. console.log(add(1)(0)(-1)(-1));
  17.  
  18. var addTwo = add(2);
  19. console.log(addTwo);
  20. var addTwo = add(2);
  21. console.log(addTwo(3));
  22. var addTwo = add(2);
  23. console.log(addTwo(3)(5));
Advertisement
Add Comment
Please, Sign In to add comment