DEV Community

loading...

Discussion on: Better loops in JavaScript

Collapse
joelnet profile image
JavaScript Joel

Great article! I noticed some minor bugs:

// This:
arr.reduce((accumulator, currentValue) => (acc += curr), 0)

// Should be:
arr.reduce((acc, curr) => (acc + curr), 0)

You can change += to just be + also.

Same goes for:

// This:
arr.reduce((acc, curr) => (acc *= curr), 1)

// Can be:
arr.reduce((acc, curr) => (acc * curr), 1)

Cheers!

Collapse
kartik2406 profile image
Kartik Malik Author

Good catch :D thank you very much :)