I was stuck on this, but understood what’s going on only after console-logging+heavy commenting+python-tutoring+reverse-engineering solution from guides. My PC freezed however, and bunch of comments was lost, that’s a bummer
For now I am trying to understand how would I modify the below code to return undefined instead of [Function]. More info in the comments.
Btw there no such tests cases in the challenge like addTogether(4), for example.
function addTogether() {
const [first, second] = arguments;
console.log(first, second)
if (!(Number.isInteger(first))) {
return undefined;
}
if (second === undefined) {
return (second) => addTogether(first, second);
}
if (!(Number.isInteger(second))) {
return undefined;
}
return first + second;
}
//addTogether(2, 3);
//addTogether(5)(7);
console.log('case only 1 argument and its a number, output:', addTogether(4))
//case only 1 arg and its a number, output: [Function]
Why are you trying to do this? It’s very different than the instructions.
I would replace the spot where you return a function with a return undefined and then every time you return a function you would instead return undefined.
Yeah, I know I am not following instructions right now.
I just was a bit stuck with this case of input:
addTogether("https://www.youtube.com/watch?v=dQw4w9WgXcQ") should return undefined
where input is 1 argument and not a number
So I did some tests as above(only 1 argument which is number) and became curious about the question I asked.
It seemed little strange:
Why my function handles cases when only 1 argument is not a number, but doesn’t handle cases with only 1 argument which is a number