First, let me say reduce() is amazing - the many awesome things you can do with it, that's been done with it, which I'll make clearer.

But then, I didn't always agree it was amazing. Really, I initially cursed after it - declaring it useful not for much. I obviously lacked understanding of this nifty little array method.

Now that I've grokked it, I want to share how I got here in case I got 7 million others who might be where I was and need to see its goodness. So, in this series called Reduce, I'll unravel (or, really, reduce) its mysteries.

Series plan

  1. What is reduce() and how I grokked it
  2. How reduce() works
  3. reduce()'s interesting nitty-gritties
  4. reduce() in action niftily

As for installment #4, since I'll be breaking down each example (of reusable functions or function recipes) in the way I read it to understand, each one will be its own post. So, in all, there might be 10 or so posts in the series.

The back story

I'd cursorily looked at reduce() before along with other array methods some two or so years ago when I was introduced to the new array methods in JavaScript. I don't remember learning anything of it then.

Then when I saw it as a topic on its own in Scott Tolinski's "Better JavaScript" course, I was fascinated. I relished that I was finally going to get an ear- and eyeful deep-dive into the method. I was disappointed, though. No offense, Mr. Tolinski, but I just didn't get that deep-dive, you know what I mean.

So, I thought, well, you know what you do, kb - you read stuff deeply wherever it is well-documented, why not go read it on the MDN docs? I did.

As I hit it the first time, scanning the entire page, I got further frustrated, thinking, what's this, anyway? It doesn't even make sense! And, even if it did, it's not useful for much more than "accumulating", piling stuff on stuff. 'Maybe I should just let it go until I saw it in some more practical use case....'

Nonetheless, I persisted in studying.

On a morning when I was still fresh and golden and young, I came back and dug in. It started to make sense. And, as it did, so did the illustrations. I thought, why not publish your very own grokking it, perhaps there may be one person out there who might benefit. Yes, 7 million out there!

The decision to publish became solid when upon stumbling on a particular example in the doc, which led me to writing a well-crafted message needing explanation from my JavaScript mentor Chris Ferdinandi, I got helped. I'd posted my question and code illustration on the Slack channel dedicated to Chris's mentee community. It was there that another student picked up my question and in a couple back-to-back conversations clarified that one example, which further opened the world of reduce()'s amazingness to me.

That amazingness is the series. Dig in, enjoy.