HN
Hacker News
Top
New
Best
Ask
Show
Jobs
Comment by eru | Hacker News Reader
Parent
Full thread
eru
·
What's the value of sum for an empty array in your example?
View on HN
ahoge
·
The 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);
Reply on news.ycombinator.com