DEV Community

Discussion on: Understanding reduce in JavaScript

Collapse
 
angelfire profile image
Andrés Bedoya

That's why it's important use well named variables, imagine that your first approach with reduce was this way:
arr.reduce((accumulator, currentValue) => accumulator + currentValue);

Much better, don't you think so? It's almost self explanatory...

Collapse
 
chrisidakwo profile image
Chris Idakwo

This is still confusing to someone who has never worked with reduce(). But then makes explaining it a bit more easy.

Collapse
 
savagepixie profile image
SavagePixie

I'm pretty sure I would still have found a way to be confused by it, hahaha

But I do agree that clear naming goes a long way to help understand code.