DEV Community

Discussion on: Reduce method with an input of a string or an object

Collapse
 
devtalhaakbar profile image
Muhammad Talha Akbar • Edited

I have myself found .reduce to be very useful however, I think one must atleast put some time in naming the accumulator comprehensively so, it is self-evident what the list of items will be reduced to. Personally, in the first example, I would have named accumulator to be sum or total. In the second example, shortestWord. In the third (tricky) example, perhaps, reverseObject and, I would have defined reverseObject to be an object that has their keys / values swapped (as a comment).

However, like Ben said, this would definitely help JS developers to not shy away from .reduce and start using it in the projects!