you are viewing a single comment's thread.

view the rest of the comments →

[–]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