The Javascript Array.reduce() method you didn’t know existed

Milos Bejda
1 min readOct 29, 2017

--

For to often I see developers do something like this

The code block loops through an array of numbers and adds them to a number outside the loop. The end result will produce a variable that contains the sum of all numbers in the array.

However, the solution can be expressed in terms that correspond to the problem being solved. Even though the results are going to be same, future developers who may inherit that code will thank you for having a clear and concise code block.

--

--

No responses yet