Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
eru
· 11y ago · 0 comments
What's the value of sum for an empty array in your example?
Comments
[–]
ahoge
11y ago
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);