Personally, I think your logic is backwards. You are checking if both arguments are valid numbers first and then trying to work your way through all the exceptions. You might consider approaching this from the other end and start by looking for when they are not numbers first and ruling those out which will then leave you with two valid numbers to add together at the end.
Also, I wouldn’t use the rest operator here, it’s only two arguments, so I think it would be much simpler to just use (a, b) that way you don’t have to mess with array notation.
Finally, I’m not sure this challenge requires you to convert strings to numbers, so I would leave that out to make this simpler. In other words, you only need to be testing if the arg is a “number”. Remember, there are other types besides “string” and “number”, such as “boolean” and “object”. Don’t you think it would be much easier to just test if an argument is not a “number” rather than testing if it is one of the other non-number types?
Maybe the solution is try check first different, I can’t use (a, b) because in the exercise need curried function. With my if…else never get and the logic say if don’t get in the first if go to else but if don’t get in my else he go to my second if. But don’t get.
This doesn’t make sense to me. Please elaborate. I can tell you that I solved this challenge using (a, b) (or if you don’t like those names use something else, like (firstNum, secondNum). Also, you are using a in your returned function. What is the value of a?
Your parameters (…a) are correct. But you need to check first if the arguments are numbers and not strings or arrays. You need to do this once for the outer function and then again for the inner one.
Since isNaN() doesn’t work in all cases, you can use typeof which is also correct! But you need to also check if the argument passed is an array or not. There is a built-in function for that.
Once you do that check, return undefined right away if the argument passes that test. Or else (if the argument is not a string neither an array), then get to the part of checking if the a.length > 1. And then again do the similar type check in your inner function also.
No, my point was to trace through the original code with that condition. Will it ever reach that last if?
As I’m saying, your original code is easily fixable. With logic, sometimes the order matters. Take this pseudo code example
if well rested
go back to sleep
set 10 minute delay
call function wakeUpInTheMorning
if house on fire
I’m suggesting that the logic is out of order. I’m suggesting that if the house is on fire, then none of that other stuff matters and the rest of the stuff will just distract from the more important issue. It’s what we call a “fail-fast” - a condition that means it’s impossible to proceed so we just fail for it right away. If the first (or any) argument is a string, there is no point in continuing. Like the 911 call, it should go at the top. It is a breaking condition that supersedes all others - there is no point in pretending to continue.
Yes, there are other ways you could simplify your logic, but moving the logic around will work. You have all the ideas there, they are just in the wrong order.