Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The problem is to write sum() such that it produces the following output -
- // console.log(sum(2,3)); // Produces 5
- // console.log(sum(2)(3)); // Produces 5
- function sum() {
- var s = Array.prototype.reduce.call(arguments, function (x, y) { return x + y; }, 0);
- var f = function () {
- var a = Array.prototype.slice.call(arguments);
- a.push(s);
- return sum.apply(null, a);
- };
- f.valueOf = function () { return s; };
- return f;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement