DEV Community

Discussion on: What s wrong with Array.reduce ?

Collapse
 
alaindet profile image
Alain D'Ettorre

What is better, using some native language syntax or calling a function for the same thing? I mean, in the following example maybe it's even easier to use reduce, but in my experience NOT using it is usually much easier.

const someStuff = [42, 69, 123, 10, 56, 9, 4, 3];

const theSum1 = someStuff.reduce((total, num) => total += num, 0);

let theSum2 = 0;
for (const num of someStuff) {
  theSum2 += num
}
Enter fullscreen mode Exit fullscreen mode