The description quite literally says "given an array of integers", yet one test gives null as the input, which results in TypeError: Cannot read property 'length' of null when correctly assuming that you always get an array (as per description) and merely need to test for its length.
Have you tried to search for documentation online? Just something like "check empty array JavaScript", "check null array JavaScript"?
You're doing it wrong. Try reading the posts below.
P.S.: your current code works.
Apparently, a lot.
This comment is hidden because it contains spoiler information about the solution
Not an issue ~~ There's this in description too
If the input is an empty array or is null, return an empty array.
The description quite literally says "given an array of integers", yet one test gives
null
as the input, which results inTypeError: Cannot read property 'length' of null
when correctly assuming that you always get an array (as per description) and merely need to test for its length.You have already decided you have either the sum of the elements or the number of elements. The tests are wrong.
I wonder how many people got it wrong at first because they mis-read the instructions XD.