<?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>Forem: Nicky Hajal</title>
    <description>The latest articles on Forem by Nicky Hajal (@nickyhajal).</description>
    <link>https://forem.com/nickyhajal</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%2F101245%2F5add0bf9-f1ef-43e4-a77f-3097bd61bf0c.jpeg</url>
      <title>Forem: Nicky Hajal</title>
      <link>https://forem.com/nickyhajal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/nickyhajal"/>
    <language>en</language>
    <item>
      <title>What to Do When Things Aren't Working</title>
      <dc:creator>Nicky Hajal</dc:creator>
      <pubDate>Thu, 04 Oct 2018 22:29:44 +0000</pubDate>
      <link>https://forem.com/nickyhajal/be-the-wind-not-the-sailboat-what-to-do-when-things-arent-working-97j</link>
      <guid>https://forem.com/nickyhajal/be-the-wind-not-the-sailboat-what-to-do-when-things-arent-working-97j</guid>
      <description>&lt;p&gt;You know what I love about programming? There are a lot of problems to solve.&lt;/p&gt;

&lt;p&gt;Every step of the way, you're taking something that doesn't do what you want it to do and finding a way to make it work.&lt;/p&gt;

&lt;p&gt;As I got better this I thought, "Cool, I'm getting to be a better programmer."&lt;/p&gt;

&lt;p&gt;Lately, I've been realizing that the fundamental skills of coding reach far outside the digital world. In fact, programming has made me &lt;em&gt;a better person,&lt;/em&gt; largely because it's taught me what to do when things aren't working.&lt;/p&gt;

&lt;p&gt;The following applies to programming but I hope you'll see that you can use it just as much in your day to day life.&lt;/p&gt;

&lt;p&gt;~&lt;/p&gt;

&lt;p&gt;Sometimes while developing software you come across a bug that you just can't seem to figure out. You swear it must be a problem with the operating system or programming language and have to remind yourself that this is almost never the case - it's your problem to fix.&lt;/p&gt;

&lt;p&gt;For a programmer, these really tough issues are, as Seth Godin puts it, &lt;a href="http://sethgodin.typepad.com/the_dip/"&gt;the Dip&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are no clear, sensible paths to go down next. You want to give up because &lt;em&gt;things just aren't working&lt;/em&gt;... but if you don't, success is just over the hill.&lt;/p&gt;

&lt;p&gt;What I've learned is that in situations like this, the only important thing is to &lt;em&gt;create motion by any means necessary&lt;/em&gt;. In other words, changing absolutely anything even remotely connected to what you're working on.&lt;/p&gt;

&lt;p&gt;Delete pieces here and see what happens there, add lines of code even to check parts you assume are working fine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Make changes that you know won't solve the problem because they still may lead you to the solution&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The only objective is to shake things up and unearth new pathways to explore.&lt;/p&gt;

&lt;p&gt;When something isn't working, put the priority on trying new things quickly instead of finding a direct route to the solution.&lt;/p&gt;

&lt;p&gt;I know this sounds crazy, but making unintuitive, "let's see what else breaks when I do this"-style changes is almost always what leads me to the hardest to find answers.&lt;/p&gt;

&lt;p&gt;Best of all, this seems to be a universal tactic; it's improved every facet of my life I've had the insight to apply it to.&lt;/p&gt;

&lt;h2&gt;
  
  
  With the Wind or Against the Wind? Either is fine.
&lt;/h2&gt;

&lt;p&gt;I'm no sailor but I know that when you're on the open seas and using the wind as your driving force, the problem isn't going into a headwind - even energy going opposite to your desired trajectory can be channeled in a useful way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The problem is when there is no wind&lt;/strong&gt;, no motion.&lt;/p&gt;

&lt;p&gt;Next time you're completely stuck imagine a sailboat lost at sea, water stretched to the horizon in all directions, with no wind.&lt;/p&gt;

&lt;p&gt;Except in this scenario, you're not the sailboat, &lt;em&gt;you're the wind&lt;/em&gt;!&lt;/p&gt;

&lt;p&gt;Start blowing any direction and let the boat harness that energy into moving the right direction.&lt;/p&gt;

&lt;h2&gt;
  
  
  When You're Stuck, Make Changes
&lt;/h2&gt;

&lt;p&gt;We treat change as if it's something rare, precious and important to get right.&lt;/p&gt;

&lt;p&gt;We believe that there's such a thing as 'good' change that works in our favor and 'bad' change that doesn't.&lt;/p&gt;

&lt;p&gt;But, it's only when you make fewer changes that it becomes more critical for each of them to have positive effects.&lt;/p&gt;

&lt;p&gt;When you, instead, start treating change as an ordinary reflex to doubt and stuckness, it has a new purpose. It becomes less about being right directly and more about exploring the unknown and discovering solutions to problems along the way.&lt;/p&gt;

&lt;p&gt;All changes become good because all of them provide answers settling your doubts one way or another so that we can move forward.&lt;/p&gt;

&lt;p&gt;~&lt;/p&gt;

&lt;p&gt;Next time you're frustrated because you can't seem to figure out why your app is crashing or your server isn't responding...&lt;/p&gt;

&lt;p&gt;Or why you can't wake up on time, or can't quite capture a character in a novel you're writing... or feel uninspired by your latest design or are just unsatisfied with some aspect of your life...&lt;/p&gt;

&lt;p&gt;Start experimenting with changes.&lt;/p&gt;

&lt;p&gt;Consider that it may be better to consciously make a few mistakes than to be stuck where you are.&lt;/p&gt;

&lt;p&gt;You can't leverage stagnation but a gust in any direction can help you discover what you need to finally get things working.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>programming</category>
      <category>beginners</category>
      <category>motivation</category>
    </item>
    <item>
      <title>Mark as read and/or private labels?</title>
      <dc:creator>Nicky Hajal</dc:creator>
      <pubDate>Fri, 21 Sep 2018 21:04:04 +0000</pubDate>
      <link>https://forem.com/nickyhajal/mark-as-read-andor-private-labels-5fkj</link>
      <guid>https://forem.com/nickyhajal/mark-as-read-andor-private-labels-5fkj</guid>
      <description>&lt;p&gt;Just a thought that my Reading list is growing, even though I'm reading things. Of course I could unmark them so they're off my reading list entirely... but it's also nice to have a log of the things I added there.&lt;/p&gt;

&lt;p&gt;So, maybe another option is being able to mark a post as read and the ability to toggle &lt;code&gt;Read posts&lt;/code&gt; on and off in the reading list.&lt;/p&gt;

&lt;p&gt;Or maybe there's a better solution!&lt;/p&gt;

</description>
      <category>meta</category>
    </item>
    <item>
      <title>Re-use personal modules via NPM/Yarn?</title>
      <dc:creator>Nicky Hajal</dc:creator>
      <pubDate>Fri, 21 Sep 2018 18:07:23 +0000</pubDate>
      <link>https://forem.com/nickyhajal/re-use-personal-modules-via-npmyarn-501g</link>
      <guid>https://forem.com/nickyhajal/re-use-personal-modules-via-npmyarn-501g</guid>
      <description>&lt;p&gt;Hey all!&lt;/p&gt;

&lt;p&gt;Just curious if anyone has a work flow for streamlining internal code-reuse between projects via npm/yarn?&lt;/p&gt;

&lt;p&gt;For example, most of my projects use &lt;code&gt;sequelize&lt;/code&gt; and have models like &lt;code&gt;User&lt;/code&gt;, &lt;code&gt;CredentialChange&lt;/code&gt;, &lt;code&gt;Transaction&lt;/code&gt;, etc. that I'd love to reuse internally.&lt;/p&gt;

&lt;p&gt;Is there a best practice for using NPM to pull in that code (ideally still in a form that I can extend).&lt;/p&gt;

</description>
      <category>npm</category>
      <category>help</category>
      <category>javascript</category>
      <category>yarn</category>
    </item>
    <item>
      <title>Why Your Best Work is Hardest to Finish</title>
      <dc:creator>Nicky Hajal</dc:creator>
      <pubDate>Thu, 20 Sep 2018 18:48:14 +0000</pubDate>
      <link>https://forem.com/nickyhajal/why-your-best-work-is-hardest-to-finish-1n9h</link>
      <guid>https://forem.com/nickyhajal/why-your-best-work-is-hardest-to-finish-1n9h</guid>
      <description>&lt;p&gt;"The professional does not over-identify with his art, but simply shows up every day to put his time in, to do the work."&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Steven Pressfield, the War of Art&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When I was 21, I dropped out of college to pursue the life I’d been imagining for years. The life where I could focus on meaningful projects that I enjoyed working on. The life where I could choose how to invest my time instead of being subjected to how others thought I should spend it.&lt;/p&gt;

&lt;p&gt;I knew I had to put in the effort and time if I wanted to succeed - and I was doing exactly that. But despite my efforts, I struggled finishing many of the projects I cared about most.&lt;/p&gt;

&lt;p&gt;Then I found &lt;a href="https://www.amazon.com/War-Art-Through-Creative-Battles/dp/1936891026/ref=tmm_pap_swatch_0?_encoding=UTF8&amp;amp;qid=&amp;amp;sr="&gt;The War of Art&lt;/a&gt; by Stephen Pressfield. It’s a book that had a profound impact on my work and the work of many others...&lt;/p&gt;

&lt;p&gt;But there was one sentence that I just hated.&lt;/p&gt;

&lt;p&gt;"The professional does not over-identify with his art, but simply shows up every day to put his time in, to do the work."&lt;/p&gt;

&lt;p&gt;My mind totally rejected this concept. I just dropped out of college to pursue what I loved, how could I not identify with it?&lt;/p&gt;

&lt;p&gt;Luckily, I continued to deliberate over that quote for some time - months, maybe years - until it finally sunk in.&lt;/p&gt;

&lt;h2&gt;
  
  
  We Don’t Finish When Too Much is On the Line
&lt;/h2&gt;

&lt;p&gt;Often when we start feeling that a particular piece of work has special, unique value we begin to identify with it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“All that practicing is really paying off!”&lt;/li&gt;
&lt;li&gt;“I can’t wait to see what Jessica thinks of this!”&lt;/li&gt;
&lt;li&gt;“This is going to be my legacy."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As you continue to blur the lines between your identity and your project, the stakes begin to rise. If your project fails, it becomes less something you can brush off.&lt;/p&gt;

&lt;p&gt;It's starts to feel like not just the failure of the project but a failure of &lt;em&gt;you&lt;/em&gt;. What people say about your project turns into something they’re saying about &lt;em&gt;you&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Maybe you show it to a friend and interpret some feedback as an attack—or maybe you just start imagining that feedback. But the more over-identified you become, the more determined you are make your work even better before getting your work out to a larger audience so that you don’t have to take any more ego-beatings.&lt;/p&gt;

&lt;p&gt;Unfortunately, that doesn't get you any closer to actually sharing your work with the people who would benefit from it.&lt;/p&gt;

&lt;h2&gt;
  
  
  When We Over-Identify with Our Work, Finishing is Incredibly Hard
&lt;/h2&gt;

&lt;p&gt;The root of the problem is simply that there’s not a separation of your personal value as a human from the value of your project.&lt;/p&gt;

&lt;p&gt;It’s very unlikely that your project needs more tinkering. What it needs to some exposure. Get your work out to 10 people. Accept their criticism with gratitude and realize deeply that they are sharing their experience with your work, not their opinion about you.&lt;/p&gt;

&lt;p&gt;There's no need to defend your work from their feedback whether you agree or not. Just accept it, say thanks and work it into the next iteration if you think it's worth a shot.&lt;/p&gt;

&lt;h2&gt;
  
  
  Love Your Craft, Not Your Projects
&lt;/h2&gt;

&lt;p&gt;The reason that it was so hard for me to accept Pressfield’s ideas about over-identifying with my work is because I loved the products I was developing (and still do). I wanted to identify with it, I wanted it to be a deeply rooted part of my life.&lt;/p&gt;

&lt;p&gt;What I came to realize over-time is that I was channeling that love towards the wrong thing: a single project. That makes you want to protect the project at all costs, which translates to shielding it from the world.&lt;/p&gt;

&lt;p&gt;If you shift that love for your work to &lt;strong&gt;love for your craft&lt;/strong&gt; the exact opposite happens. You realize that &lt;strong&gt;you improve so much faster&lt;/strong&gt; when you get your work out into the world. You start sharing work as fast as you can to whoever it may help. &lt;/p&gt;

&lt;p&gt;Commit to your craft, don’t over-identify with your projects and let your best work see the light of day.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>career</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Demystifying Array.reduce(): How to understand it and when to use it in your code</title>
      <dc:creator>Nicky Hajal</dc:creator>
      <pubDate>Wed, 19 Sep 2018 01:31:07 +0000</pubDate>
      <link>https://forem.com/nickyhajal/demystifying-arrayreduce-how-to-understand-it-and-when-to-use-it-in-your-code-5b96</link>
      <guid>https://forem.com/nickyhajal/demystifying-arrayreduce-how-to-understand-it-and-when-to-use-it-in-your-code-5b96</guid>
      <description>&lt;p&gt;ES5 and later versions of JavaScript brought several new methods for handling arrays. Many of them have become the best practice for common tasks with arrays and JavaScript is much better off with them.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Array.map()&lt;/code&gt; and &lt;code&gt;Array.filter()&lt;/code&gt; are two examples of daily-driver ES5 additions that are staples for most JS developers.&lt;/p&gt;

&lt;p&gt;An equally useful but often less understood tool in the kit is &lt;code&gt;Array.reduce()&lt;/code&gt;. Lately, I've been using &lt;code&gt;reduce&lt;/code&gt; more often, but it took a while for it to feel natural and I often see other developers struggling with it... or just not using it at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reduce is often taught wrong and therefore misunderstood
&lt;/h2&gt;

&lt;p&gt;In my opinion, a large reason for the confusion is that &lt;code&gt;reduce&lt;/code&gt; is just taught wrong. In fact, it even feels &lt;em&gt;named&lt;/em&gt; wrong to me (even though, of course, the concept and name of a reducer come from well before it was added to JavaScript).&lt;/p&gt;

&lt;p&gt;The most common example when teaching reducers is something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;accumulator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentItem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;accumulator&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;currentItem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// sum = 10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This fairly cleanly shows how reducers function. You call &lt;code&gt;reduce()&lt;/code&gt; on an array and pass it an initial value as well as a function that runs for each item of that array.&lt;/p&gt;

&lt;p&gt;To the passed function, &lt;code&gt;reduce&lt;/code&gt; sends: &lt;/p&gt;

&lt;p&gt;1) The current item and&lt;br&gt;
2) The value returned by the previous callback (or the initial state, when called for the first time)&lt;/p&gt;

&lt;p&gt;The final value of &lt;code&gt;reduce&lt;/code&gt; is ultimately whatever the inner reducer function returns when called the last time.&lt;/p&gt;

&lt;p&gt;As a result, in this case, the reducer is summing the values of the array and returning the total value.&lt;/p&gt;
&lt;h2&gt;
  
  
  So... adding arrays of numbers, is that all &lt;code&gt;Reduce&lt;/code&gt; does?
&lt;/h2&gt;

&lt;p&gt;I saw that example so many times, but rarely saw explanations that went much further.&lt;/p&gt;

&lt;p&gt;"Hm, interesting.", I'd think, as I went on with my day.&lt;/p&gt;

&lt;p&gt;So, what's the real deal with reducers? What are they actually good for?&lt;/p&gt;

&lt;p&gt;Here's the real power:&lt;/p&gt;
&lt;h2&gt;
  
  
  Reducers are useful when you want to process an array &lt;strong&gt;but output something that isn't an array&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;That's really what it boils down to, and that is useful &lt;em&gt;very often&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;After all, isn't that what we're doing in the example above? We're taking in an array and returning an integer. In that context, it makes some sense that we're "reducing" the array, but we don't always have to output something as simple as an integer.&lt;/p&gt;

&lt;p&gt;Take this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;trips&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;car&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dist&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;foot&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dist&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;flight&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dist&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;212&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;car&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dist&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;foot&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dist&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt; 

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;distanceByType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;trip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;curr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dist&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;curr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;out&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;out&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;dist&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;out&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;dist&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;out&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{});&lt;/span&gt;

&lt;span class="c1"&gt;// distanceByType = {car: 132, foot: 10, flight: 212};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So here, we're taking in an array, but returning an object of sums, instead of just a single one. &lt;/p&gt;

&lt;p&gt;Here we're beginning to see the essence of what a reducer really is:&lt;/p&gt;

&lt;h2&gt;
  
  
  A reducer is a transformer
&lt;/h2&gt;

&lt;p&gt;It takes in an array and transforms it into something else.&lt;/p&gt;

&lt;p&gt;Thinking of it in this way not only helps me understand what &lt;code&gt;reduce&lt;/code&gt; does but also &lt;em&gt;helps me realize when I should be using it&lt;/em&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Have an array of users but want to output a string like, &lt;code&gt;Mike, Becka and 3 others will be attending&lt;/code&gt;? A reducer is great for that!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Have an array of articles and want an object with them keyed by category? A reducer is great for that!&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The use cases go on and on.&lt;/p&gt;

&lt;h1&gt;
  
  
  Go forth and &lt;code&gt;Array.reduce()&lt;/code&gt;!
&lt;/h1&gt;

&lt;p&gt;I really hope that helps and would love to clarify things further in the comments if I can.&lt;/p&gt;

&lt;p&gt;Got a use case for &lt;code&gt;reduce&lt;/code&gt; that you love? Comment below and I'll add it to the article 🚀&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>react</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
