Hi campers! After a long struggle I managed to pass this algorithm challenge, but I’ve got some doubt. With the following code the challenge is succesfully passed but when i call the function with a single argument it will return function (x) {return .......}
instead of a number, also if I set a value for the x variable. I’ve noticed that the same issue is common to all the solutions given in the relative wiki. Any suggestion on how to make it work the right way also with a single argument?
#spoiler!
function addTogether(args){
if(arguments.length == 1 && typeof arguments[0] == "number") {
return function(x) {
return addTogether(args, x);
};
}
if(arguments.length == 2 && typeof arguments[0] == "number" && typeof arguments[1] == "number") {
return arguments[0] + arguments[1];
}
}
addTogether(2);