DEV Community

Discussion on: 👨🏻‍💻 UnderStand the Most Powerful 💪 Function of Javascript

Collapse
sharmakushal profile image
Kushal sharma Author

Aggred with you , i just want to show that you can also you reduce for map amd filter also

Collapse
jamesthomson profile image
James Thomson

I see... but why? Perhaps this is the disconnect in your article. Yes, you can use reduce to achieve other tasks, but why do so when there are more succinct functions? I mean, I could use a for loop for all of these as it's the basis of all these function, but I wouldn't do so unless I had good reason (performance can be one of those or the need to break out of the loop at any given time which you can't do with these).

The title of your article claims reduce is the most powerful javascript function (which is definitely debatable), but doesn't really explain or demonstrate why you say that. If using reduce were 5x faster than filter or map then the claim could be relevant, but that's not the case. I don't mean to be confrontational, hopefully you take this as a positive critique, I just don't see the correlation of your statement in the title of this article.

Thread Thread
digianpaul profile image
Paul DiGian

The point he is trying to make is that it is possible to implement filter and map in terms of reduce but it is not possible to do the inverse.

Indeed it is a well know theoretical fact.

Thread Thread
jamesthomson profile image
James Thomson

If that's the case, I don't think it comes across very well in the article. I understand reduce can be used in different ways, but so can many other things in JS. That doesn't mean they should be used this way. I'm not trying to degrade his article, I just think it's important to explain why you would do it this way or why it's interesting, but not something that should be practiced. There are a fair number of beginners (this article is even tagged with #beginner) on Dev.to and I think it's alarming to be encouraging a certain style of programming that would be torn apart in a code review.