Advertisement
Guest User

Untitled

a guest
May 25th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. // The problem is to write sum() such that it produces the following output -
  2. // console.log(sum(2,3)); // Produces 5
  3. // console.log(sum(2)(3)); // Produces 5
  4.  
  5. function sum() {
  6. var s = Array.prototype.reduce.call(arguments, function (x, y) { return x + y; }, 0);
  7. var f = function () {
  8. var a = Array.prototype.slice.call(arguments);
  9. a.push(s);
  10. return sum.apply(null, a);
  11. };
  12. f.valueOf = function () { return s; };
  13. return f;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement