Introduction to Currying and Partial Application.....program.exe not working

Tell us what’s happening:
I didn’t understand difference between partial and currying functions. Can somebody explain it to me ?

Your code so far


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);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application

Currying is taking a function of multiple arguments and converting it into a function of one argument. Partial application is when you call such a curried function and get back a function expecting more arguments. For more detailed info, including some examples, see this SO answer:

1 Like

Thanks for the link, that improved my understanding.

Does that mean Partial functions can include curried function as it’s innermost argument ?

For that adder example you posted that takes three arguments, the first two functions you get back would be considered curried, and the last one a normal function from a number to a number. That’s mathematically speaking, anyway; in terms of programming, it’s all just plain functions, which can always take another function as an argument or return other functions. It’s a fun programming pattern to play with, and can bend your brain into funny shapes :slight_smile:

1 Like