Arrow functions in Introduction to Currying and Partial Application

Tell us what’s happening:

I don’t think I need arrow functions, but I’ve reading a lot about arrow functions being used in currying and partial applications to hold the data and pass that to the next element…sort of like a function flow-form down to the ultimate function, which processes all previous partial functions.

I’m not passing the test. I don’t think I understand currying, partial application correctly, so I’d appreciate if someone broke down my code and explained where I’m missing the point.

Your code so far


function add(x) {
  // Add your code below this line
 x => {
   y => {
      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/71.0.3578.98 Safari/537.36.

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

You are missing return.

{} in JS is the syntax for a block. It can contain anything, but you need to return things out of it.

So that writing tiny callback functions isn’t a pain, if you don’t put the body of the function in curly braces, it will just implicitly return whatever you put there, but in that case you can’t have more than one expression.

Edit: yes, arrow functions aren’t special with respect to this, it’s just that they take less typing

function add(x) {
  return function (y) {
    return function (z) {
      return x + y + z;
    }
  }
}

When arrow functions use {} a return statement is required. For example:

function add(x) {
  // Add your code below this line
  return y=>{
    return z=>{
      return x + y + z
    }
  }
  
  // Add your code above this line
}
add(10)(20)(30);

Also, x is already being passed in, so no need to pass it again.