DEV Community

Discussion on: 9 years on, I still google "javascript for loop"

Collapse
 
devdufutur profile image
Rudy NappĂ©e • Edited

So don't use explicit loops 😅

new Array(10).fill(0)
  .map((elt, idx) => idx)
  .reduce((acc, elt) => acc + elt, "")
Enter fullscreen mode Exit fullscreen mode
Collapse
 
eljayadobe profile image
Eljay-Adobe

The best part of using this instead of a for loop: you'll never remember what you're supposed to search for on Google, so you'll be forced to memorize the pattern!

Collapse
 
devdufutur profile image
Rudy Nappée

Maybe this way of doing could seem a little overkill but has advantages :

  • No mutation
  • Each step in the pipeline of transformation is visible instantly
Thread Thread
 
eljayadobe profile image
Eljay-Adobe

Not overkill in my book. I'm a fan of Elm and F# and Haskell. I think this kind of FP approach will supplant OO in time.