Tell us what’s happening:
I couldn’t figure out how to pass tests 3 and 6 so used the solution to try to understand what’s happening.
I’m confused on what the function is actually doing on the last line. I tried to use debugger to watch what it was doing, I thought it might have been reducing the array to just the number but it didn’t look like that happened. Can anyone help explain what it is doing?
Also I tried to refactor in some other ways to make sure I understood how everything else was working together and found that trying to write the function func not as an arrow function(see example) broke it. Why would changing it from an arrow function to a longer version change how the function works? I tried reading up on arrow functions on MDN but couldn’t find anything. Thanks for any help.
if (typeof second === ‘undefined’) {
return function (second) {
return sum(second);
It looks like it’s just running it back through the function that will return undefined.
I guess I just didn’t get how it strips the array to return the number
It is returning an anonymous function that accepts an argument. When called the anonymous function will run the sum function and pass it the argument. If the value provided to sum is a number it will run the if statement code block otherwise it will run the else block.
Not sure what you mean by this? It’s checking for typeof number, an array is not of type number so it returns undefined (for the test case addTogether(2)([3])).