Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. function add(){var a,v,n,f;a=[].slice.call(arguments),v=a[0]||0;if(a.length){n=a.slice(1).reduce(function(s,x){return s+x},v),f=add.bind(0,n);f.valueOf=function(){return n};return f}return v}
  2.  
  3. function test(a, b) {
  4. if (a == b) {
  5. console.log('OK');
  6. } else {
  7. console.log(a + ' != ' + b);
  8. }
  9. }
  10.  
  11. test(add(1, 2), 3);
  12. test(add(3)(4)(), 7);
  13. test(add(3)(4)(5), 12);
  14.  
  15. var three = add(3);
  16. var four = add(4);
  17. test(three, 3);
  18. test(four, 4);
  19. test(three(5), 8);
  20. test(three(6), 9);
  21. test(three(four), 7);
  22. test(three(four)(three(four)), 14);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement