Tell us what’s happening:
| can’t seem to call another function. The problem facing addTogether(2)(3).
Cheers! Your code so far
function addTogether() {
var arrNum = [];
for (let i = 0; i < arguments.length; i ++) {
if (Number.isInteger(arguments[i])){
arrNum.push(arguments[i])
} else {
return undefined;
}
}
if (arrNum.length === 2)
return arrNum.splice(0, 2).reduce((a, b) => a + b);
else {
return function(y){
return + y;
};
}
}
console.log(addTogether(2)(3));
// return [...arguments].reduce((a, c) => a + c);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36.
Look what you are returning here. You should be return something added to y.
Assuming you figure out what should precede the + y above, the last test case addTogether(2)([3]), is probably going to be a problem with your current logic. It will depend on how you fix the above issue.
NOTE: Just remember that when you return the function, that function will need to validate that the argument passed is a number. You have no logic in the returned function that would perform this validation.