DEV Community

Discussion on: What’s your alternative solution? Challenge #6

Collapse
lukaszahradnik profile image
Lukáš Zahradník • Edited on

This is an example of wrong usage of map.

Collapse
13point5 profile image
Bharath Sriraam R R

May I know what you mean by "wrong"? If you mean inefficient please do elaborate, I would like to hear about it!

Thread Thread
lukaszahradnik profile image
Lukáš Zahradník • Edited on

Well, it is inefficient as well.

In this example the map is just exploited for iterating over elements and completely ignores purpose of the function (transforming array to a new array). It would be better to use forEach or reduce instead.

Thread Thread
13point5 profile image
Bharath Sriraam R R

Good point, thank you!