Arguments Optional 7/19

Tell us what’s happening:
Hey Fellow Campers -

I’m trying to get through this one without looking at the hint lol. I’ve got 3 of the tests passed. But currying the function I’m finding difficult. Now I can pass the curry test making a curried function, but then the other tests fail.

I’m not sure how to combine a curried function with non-curried function. If I do this as a curried function, I have no idea how to modify it to work with the rest of the functions.

function add(x) {
// Add your code below this line

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

// Add your code above this line

}

This is my code so far without the curried part. Thanks and code on!

Your code so far


function addTogether() {

    var args = Array.prototype.slice.call(arguments); // creates an array with arguments
    console.log(args);

    
    for (let i = 0; i < args.length; ++i) {

    console.log(args[i]);
    if (typeof args[i] !== 'number') {
      return undefined;
      }
    }
  
    return args.reduce(function (previousValue, currentValue) { // adds and returns the sum
      return previousValue + currentValue;
    });
}

addTogether(2,3);

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/arguments-optional/

You have the right idea, do something conditionally with the arguments - there’s nothing stopping you writing each condition and returning the correct type, remember you can return a function or a number from the same function, thanks to the very dynamic nature of js

Honestly I don’t like this question for similar reasons as you, javascript’s function syntax doesn’t lend itself well to curried and uncurried function conversions very easily, though I guess you could use bind in a sense here

And though that reduce you have in there is a good idea, it’s not what this question wants really, it only wants you to consider up to two values

Thanks again for the help @gebulmer. I ended up looking at the hint after spending 30 minutes trying different approaches and searching google.

I see now that you can basically curry a function at any point within a function. As you were saying I simply need to realize that you can create if statements for everything you need and return the proper the result or function accordingly.

I didn’t realize I’d need so many checks till I saw the solution, but after seeing the solution - I can at least read this one and it makes sense.

Honestly this is such an odd question, don’t feel bad about not getting it right away

I don’t understand why this isn’t passing…