Add a new solution to: Introduction to Currying and Partial Application

Hi there! I am a beginner so please correct me if this is not a valid solution. I’d like to suggest adding another solution to this lesson: freeCodeCamp Challenge Guide: Introduction to Currying and Partial Application

I’m unsure how to write the solution code so it expands/closes but here’s another solution I think would be valid based on the examples in the original problem:

return add = x => y => z => x + y + z

Original problem: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application

Hello there.

Thank you, for your contribution. For future contributions, please wrap your solution within :

[details]
```
code goes here...
```
[/details]

Also, provide all of the necessary code to pass the challenge.

You have a return instead of a declaration for the add function.

return add = x => y => z => x + y + z

Should be:

const add = x => y => z => x + y + z;

Thank you, for your guide post contribution. I have taken your suggestion, and included it in the following guide post:

I did slightly alter the expression to not return the function add expression.

We look forward to your further contribution.

1 Like

@Sky020 For the example you added it seems a bit odd to have the add function as a function declaration with an arrow function inside it. Why not just make it an arrow function?

We can add parentheses to the parameters if that makes it clearer (e.g. prettier does this).

const add = (x) => (y) => (z) => x + y + z;
console.log(add(10)(20)(30)); // 60

Not sure if having another example that shows each function call would be useful, just to clearly show what is happening?

const add = (x) => (y) => (z) => x + y + z;

const innerFn1 = add(10);
const innerFn2 = innerFn1(20);
const result = innerFn2(30);

console.log(result); // 60
1 Like

@lasjorg, that would look better, but we should not change the seed:

function add(x) {
  // Only change code below this line


  // Only change code above this line
}
add(10)(20)(30);
1 Like

We are just showing an example, one that will pass all the tests. Not sure what the seed code has to do with it?

In my opinion, the camper should be allowed to change the initial code, as long as the code passes all the tests.

1 Like

I think this would have to go in its own discussion - whether or not we change the seed. I believe the solutions in the guide posts should follow a structure, and not just be enough to pass, because there are many challenges that can be passed with code that does not even do anything (eg. when the tests use regex, then a bunch of comments can pass, but should not be considered solutions).

The reason I took this suggestion is: it acts as a solution, to challenge interested campers to see something a bit more advanced (arrow functions, for shorter code).

In general, I would hope all of the _Solution 1_s are good code, with best-practices to pass the challenges. Then, the other solutions could contain Golf-Code-type code; something different, and fun.

1 Like

I think having a real-world example of how this would look using an arrow function is a lot more valuable than staying within the restrictions that are given for this challenge (i.e. the Add your code here comments).

Not even sure why the code comments are there other than maybe to avoid the camper renaming the function. There are no test restrictions other than the function name that would require the camper to not be allowed to change the function to an arrow function.

I mean the arrow function version is the solution we have in the solution code, so I don’t see why it shouldn’t be in the example solutions?

1 Like