• AcesOfGlorycommented on "Sum without highest and lowest number" kata

Note: If initialValue isn't provided, reduce will execute the callback function starting at index 1, skipping the first index. If initialValue is provided, it will start at index 0.

If the array is empty and no initialValue was provided, TypeError would be thrown. If the array has only one element (regardless of position) and no initialValue was provided, or if initialValue is provided but the array is empty, the solo value would be returned without calling callback.

The initial value is like a backup value for when it's empty/only one item or there's a NaN value at index 0. Since reduce works by looking at index 0, if there's nothing there it returns an error.

• kreitzocommented on "Sum without highest and lowest number" kata

cool thanks!
Why does it need a starting value of 0? it already starts at 0 doesn't it?

``````[0,1,2,3].reduce((a,b)=>a+b);
``````

is the same as

``````[0,1,2,3].reduce((a,b)=>a+b, 0);
``````
• AcesOfGlorycommented on "Sum without highest and lowest number" kata
1. First, your 'or' operator in the ternary conditional allows null values to pass through since `array !== []` is true. This means it will try to sort the null value; leading to an error.
2. Your reduce function needs a starting value (what you want it to initially be, which will be 0). Simply add a comma and a zero after the addition operator -> .reduce((a,b)=>a+b, 0)
• AcesOfGlorycommented on "Sum without highest and lowest number" kata

`typeof(null) = "object"`

You are doing `if typeof(null) == "null"` and therefore the code fails. You should directly compare a null and not use a type comparison. The null value has not been 'caught' and then it tries to read the length of this value, which produces this error.

• kreitzocommented on "Sum without highest and lowest number" kata

This comment is hidden because it contains spoiler information about the solution

• ARPerry87commented on "Sum without highest and lowest number" kata

What language are you having the issue in?

• christineurbancommented on "Sum without highest and lowest number" kata

This comment is hidden because it contains spoiler information about the solution

• SteffenVogel_79commented on "Sum without highest and lowest number" kata

You have to check first for null and then access the array. ;-)
"var highest = array[0];" is the first access....

• christineurbancommented on "Sum without highest and lowest number" kata

This comment is hidden because it contains spoiler information about the solution