3 ms·
What's the value of sum for an empty array in your example?
by eru 11y ago
What's the value of sum for an empty array in your example?
- ahoge 11y agoThe reduce one needs an initial value of 0 for that to work. Then both versions will return 0 if the array is empty. array.reduce((a, b) => a + b, 0);