My solution is very similar to the model solution. So can anyone tell me what Im doing wrong here? I always get this
TypeError: addTogether(…) is not a function error for some reason. Am I currying the function properly or am i doing something wrong here?
function addTogether() {
if (typeof arguments[0] === "number" && typeof arguments[1] === "number") {
if (arguments.length > 1) {
return arguments[0] + arguments[1];
} else {
let x = arguments[0];
return function(arg) {
if (typeof y !== "number") {
return undefined;
}
return x + arg;
}
}
} else {
return undefined;
}
}
addTogether(5)(7);
If you invoke addTogether with one argument, what do you think arguments[1] will be? A number or undefined? Since I have not run your code, I believe the outer if evaluates to false as a result you are returning undefined. undefined() leads to the above error. You are only returning a function if certain conditions evaluate to true. What if those conditions evaluate to false? Most likely that is where the clue is.
@nibble is right, and also, if you know you will have two arguments or less (and i remember that this is the case in this challenge) just use a and b or anyting like that, it’s way more comfortable