DEV Community

Discussion on: Stop using Array.map() everywhere 🥵

Collapse
 
nssimeonov profile image
Info Comment hidden by post author - thread only visible in this permalink

So basically: "don't be stupid, use the right tool for the job". Duh... really?!

I have a question - aren't you doing code reviews in your company? Why do you need to write an article just to point out to newbies, that besides Array.map they have to learn what other methods exist and use them properly?

Oh and give a ridiculous example that is accessing a variable outside the function AND the foreach statement, when all you need in this case is Array.reduce:

const fruits = ["apple", "orange", "cherry"];
let text = fruits.reduce((result,item,index) => result + index + ": " + item + "\n", '');

console.log(text);
Enter fullscreen mode Exit fullscreen mode

Please take some time to study what other options you have before writing articles.

Some comments have been hidden by the post's author - find out more