freeCodeCamp Challenge Guide: Introduction to Currying and Partial Application

Introduction to Currying and Partial Application


Problem Explanation

Use currying to return a function which accepts a function as a parameter. Each function should accept one parameter, and the third-most should return the sum of each paramater.

Relevant Links


Hints

Hint 1

Within the add function, return a function which returns a function, which returns the addition of three parameters (one from each function).


Solutions

Solution 1 (Click to Show/Hide)
function add(x) {
  // Add your code below this line
  return function(y) {
    return function(z) {
      return x + y + z;
    };
  };
  // Add your code above this line
}
add(10)(20)(30);
Solution 2 (Click to Show/Hide)
function add(x) {
  // Add your code below this line
  return y => z => x + y + z;
  // Add your code above this line
}
add(10)(20)(30);
40 Likes