0

I know it's considered bad practice here to solve homework, so I'm just asking for some direction, since I'm at a total loss. Here is the problem: Define a function add() that adds numbers in a functional manner. For example add(1)(1)(1)(1)(1) returns 5. Second example:

var addTwo = add(2);
console.log(addTwo); // 2
console.log(addTwo(3)); // 5
depressor
  • 17
  • 5

1 Answers1

0

As mentioned in the notes it is called currying. Here is a simple example of what is going on:

// uncurried
var example1 = function (a, b, c) {
    // do something with a, b, and c
};

// curried
var example2 = function(a) {
    return function (b) {
        return function (c) {
            // do something with a, b, and c
        };
    };
};

Take a look at the link to get the full picture. Good luck.

ChewOnThis_Trident
  • 2,105
  • 2
  • 18
  • 22