<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Phillip Kent Knight</title>
    <description>The latest articles on DEV Community by Phillip Kent Knight (@phillipkent).</description>
    <link>https://dev.to/phillipkent</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F209175%2F09cad5b4-d80d-452b-8a8e-4363efd66213.jpg</url>
      <title>DEV Community: Phillip Kent Knight</title>
      <link>https://dev.to/phillipkent</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/phillipkent"/>
    <language>en</language>
    <item>
      <title>I spent an entire Saturday trying to understand .reduce()</title>
      <dc:creator>Phillip Kent Knight</dc:creator>
      <pubDate>Tue, 27 Aug 2019 21:14:39 +0000</pubDate>
      <link>https://dev.to/phillipkent/i-spent-an-entire-saturday-trying-to-understand-reduce-27m2</link>
      <guid>https://dev.to/phillipkent/i-spent-an-entire-saturday-trying-to-understand-reduce-27m2</guid>
      <description>&lt;p&gt;Lately, I've been trying to up my js skills… including a run through some Javascript courses on Codecademy, which I was totally crushing until I got to reduce()… 🤯!!&lt;/p&gt;

&lt;blockquote&gt;
&lt;q&gt;The reduce() method executes a reducer function (that you provide) on each element of the array, resulting in a single output value.&lt;/q&gt; &lt;cite&gt;(per &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;)&lt;/cite&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  That description did nothing for me.
&lt;/h2&gt;

&lt;p&gt;I had no problem working through and understanding other array handling methods like filter() and map()... but I hit a roadblock trying to grasp what &lt;em&gt;reduce&lt;/em&gt; was all about. And I spent an entire day on it. &lt;/p&gt;

&lt;p&gt;But now, I &lt;strong&gt;think&lt;/strong&gt; I finally get it: we "reduce" an array of objects into one object by performing a function on each item in an array, saving the result at each step to an &lt;em&gt;accumulator&lt;/em&gt;. It's kind of like the way we use a &lt;em&gt;for loop&lt;/em&gt;, but here we're adding to (&lt;em&gt;accumulating&lt;/em&gt;) just one result. &lt;/p&gt;

&lt;p&gt;This "accumulator" thing, as I now imagine it: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbkx0mzwqdz5q8j3foajf.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbkx0mzwqdz5q8j3foajf.gif" alt="Animation of accumulator value: a + b = ab, ab + c = abc, and onward through an array of the English alphabet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If that doesn't help, here are the examples I wrote for myself to make sure I understood the basic nature of the accumulator. &lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/phillipkent/embed/KKPmPXj?height=600&amp;amp;default-tab=js&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How I got here
&lt;/h2&gt;

&lt;p&gt;To get to this level of understanding, I had to look at MDN, blogs, youtube, and finally give up and ask a more experienced programmer (my friend Dave) to explain it to me like I was five. &lt;/p&gt;

&lt;p&gt;This was what I got as an example: &lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/phillipkent/embed/MWgmWzE?height=600&amp;amp;default-tab=result,js&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
 &lt;/p&gt;

&lt;p&gt;While I now understand what's going on above, I didn't when I first saw it. &lt;/p&gt;

&lt;h2&gt;
  
  
  The resources that clicked for me
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Finally&lt;/strong&gt;, after several hours, I started to &lt;em&gt;get it&lt;/em&gt; somewhere around my third read of &lt;a href="https://jasonbelcher.dev/mapfilterreduce#reduce-implementation" rel="noopener noreferrer"&gt;Jason Belcher's post: "Map, Filter, and Reduce"&lt;/a&gt;, which actually demonstrates rolling your own reduce-like function, and my second watch of the below video from &lt;a href="https://www.youtube.com/watch?v=-LFjnY1PEDA" rel="noopener noreferrer"&gt;The Coding Train&lt;/a&gt; on YouTube. &lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/-LFjnY1PEDA"&gt;
&lt;/iframe&gt;
 &lt;/p&gt;

&lt;p&gt;If you've made it this far down the page, you might be as frustrated and confused (and determined) as I was - I hope these links will help you like they did for me me!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>explainlikeimfive</category>
    </item>
  </channel>
</rss>
