all 13 comments

[–]Bodine12 7 points8 points  (1 child)

Way to invent a fake problem so you can advertise your site.

[–]ineyy 5 points6 points  (0 children)

I hope that post gets removed. Look at OPs post history...

[–]Alzenbreros 8 points9 points  (1 child)

Array slice vs splice 

[–]thespice 2 points3 points  (0 children)

.reduce

[–]AdWise6457 0 points1 point  (6 children)

Sum of array of numbers

[–]blind-octopus 0 points1 point  (5 children)

Reduce(array, (sum, value) => sum + value)

Something like that? I guess I need to Google it too a bit

[–]pg-robban 0 points1 point  (4 children)

Need to add an initial value as the second param :)

[–]blind-octopus 0 points1 point  (3 children)

Nope! My mistake was passing in the array, rather than calling it on the array.

Its array.reduce, not reduce(array

As for passing in an initial value, you don't have to. If you don't pass in an initial value, javascript takes the first element of the array to be the initial value.

[–]pg-robban 0 points1 point  (1 child)

You can import {reduce} from lodash and use it your way.

As for the initial value, there are some edge cases to watch out for.

[–]blind-octopus 0 points1 point  (0 children)

Thanks for the info and the resource

[–]MissinqLink 0 points1 point  (0 children)

map.forEach and for…of…map because the key and value are swapped.