Skip to content
loading...

Why you should give Array.prototype.reduce() a chance too?🧐

comscience profile image kapeel kokane twitter logo github logo ・1 min read  

Let's Admit,

There is that one array method (usually .map or .forEach) which is close to our heart ❀️ and that is the one which we try to use for basically all array operations!

All of you are secretly admitting to the above sentence and thinking, "Is it wrong to do that?"πŸ€”. Well, maybe, may not. But there's no harm in learning something new, right?

In this video, we look into a long time underrated child of Array.prototype and look into whether it covers some of our day to day use cases where the poor old map/forEach is forcefully shoved to work!

Hope that helped, cheers!

twitter logo DISCUSS (3)
Discussion
markdown guide
 

I though this was on the topic of overusing reduce which was brought up by Jake Archibald recently on twitter.

They were arguing that beside summing, reduce should be avoided in favor of for loops as they were easier to read and faster.

Object.fromEntries can help remove a lot of reduces too when generating objects.

If you want a method to rule them all, reduce is your best bet, but don't.

Learn map and filter they have very clear and distinct roles, now days I favor for..of over forEach.

 

Yes correct. I brought this up to highlight the other sentiment which is: 'use map/forEach all the time', even in cases where reduce could have been your best bet.
This is another awesome video on the same topic:

 
Classic DEV Post from Jul 26 '19

🎩 JavaScript Enhanced Scss mixins! 🎩 concepts explained

In the next post we are going to explore CSS @apply to supercharge what we talk about here....

kapeel kokane profile image
Coder by day, Content creator by night, Learner at heart!