Rarely forEach, normally for..of - a podcast by Kent C. Dodds

from 2021-02-06T01:14:15

:: ::

Hey friends. So today I wanted to talk about looping over a raise and stuff
like that. And pretty much I'm mostly want to talk about for loops. Early
on in my software developer career that's pretty much exclusively how I
looked over things and I learned about filter and map and reduced and allof those things and for each and all that and I went full in on that stuff.
More recently, I've been getting into using four of loops for stuff. And I
find that to work out really nicely.To the point where I don't think you'll
ever ever catch me use a for each on an array anymore I and like I can't
think of a scenario where that would be more simple than just doing a fourof loop.
With potentially the exception of you've got a function over here already
to find and you're just gonna pass it as the argument to for each. Maybe
that I guess could make sense but most of the time I'm just gonna be using
a forever. So anyway, I Yeah, I don't really have much more to say about
that.It's just kind of.Something interesting to think about and I do have a blog
post actually about using map and filter versus reduce and a regular oldsea style loop where you have the index and everything like that. And so
you could go take a look at that if you're interested in diving little
deeper, it even has an egg-head video on there.But yeah, just look at my blog look for reduce or filter. You'll find it on
there. But yeah, I find myself like early on. I used those sea style loopsand,Then and full on a raise and now I'm kind of yeah between array
methods, sometimes I'll use reduced but not often I'm mostly on filter andmap.
If I really need performance gains of using reduced then I'll go with that
just fine but anyway hope that is interesting and useful and insightful. Ifyou haven't been using four ofs and you've been finding you're using for
each then yeah, go ahead and give a four of trying they're pretty great.
Thanks bye.

Further episodes of 3 Minutes with Kent

Further podcasts by Kent C. Dodds

Website of Kent C. Dodds