<?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: Ricardo Delgado</title>
    <description>The latest articles on DEV Community by Ricardo Delgado (@rdelga80).</description>
    <link>https://dev.to/rdelga80</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%2F72654%2F42812d25-1837-4f15-a4f0-46b103380f64.jpeg</url>
      <title>DEV Community: Ricardo Delgado</title>
      <link>https://dev.to/rdelga80</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rdelga80"/>
    <language>en</language>
    <item>
      <title>Easily Handle Component Versioning with Vue3</title>
      <dc:creator>Ricardo Delgado</dc:creator>
      <pubDate>Thu, 29 Apr 2021 15:09:18 +0000</pubDate>
      <link>https://dev.to/rdelga80/easily-handle-component-versioning-with-vue3-48n8</link>
      <guid>https://dev.to/rdelga80/easily-handle-component-versioning-with-vue3-48n8</guid>
      <description>&lt;p&gt;VueJs is known for its simplicity and low learning curve, helping launch apps from beginners to senior devs alike.&lt;/p&gt;

&lt;p&gt;But anyone who's spent time building up a codebase in Vue has learned with growth comes pain. Because of that it's important to address those scalable issues early on before an organization is stuck in a quagmire of tech debt and spaghetti code that can take days, weeks, and even months to correct.&lt;/p&gt;

&lt;p&gt;Versioning components is one of those issues that can rub against a developers ego, but to care for "6 months in the future you", versioning components is an incredibly important time and energy saving strategy.&lt;/p&gt;

&lt;p&gt;Tools like &lt;a href="https://bit.dev/"&gt;bit.dev&lt;/a&gt; handle this issue very well, but I'm preferential to duck tape and toothpick homegrown solutions that work just as well as a service that can cost upwards of $200 per month.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Do I Need To Version Components
&lt;/h3&gt;

&lt;p&gt;If you're asking this question then you haven't had to deal with a design team that gets a new lead.&lt;/p&gt;

&lt;p&gt;If you're asking this question then you haven't found a new library that more efficiently handles an issue that had been buggy since it's inception.&lt;/p&gt;

&lt;p&gt;If you're asking this question then you haven't attended a Vue Conference and walked away thinking "duh, why haven't I always done it that way?"&lt;/p&gt;

&lt;p&gt;In other words, your code &lt;em&gt;will&lt;/em&gt; change, and in Vue if it's a component that's implemented in a hundred different files, then you will be kicking yourself as you &lt;code&gt;ctrl+shift+F&lt;/code&gt; your way through your codebase.&lt;/p&gt;

&lt;h3&gt;
  
  
  Standard Component Usage
&lt;/h3&gt;

&lt;p&gt;For this example, we'll take a simple Vue Button Component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt;
     &lt;span class="na"&gt;:class=&lt;/span&gt;&lt;span class="s"&gt;"['button', &lt;/span&gt;{ block, color }]"
     @click="$emit('click')"&amp;gt;
     &lt;span class="nt"&gt;&amp;lt;slot&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;defineComponent&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@vue/composition-api&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;defineComponent&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;block&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;color&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="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;primary&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;

  &lt;span class="nx"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&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;colors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;primary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;secondary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;purple&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`style-&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where things get tricky is if you decide to take a new approach to how you want colors to set. Rather than using a named color table it'll instead act as a pass through style.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt;
     &lt;span class="na"&gt;:class=&lt;/span&gt;&lt;span class="s"&gt;"['button', &lt;/span&gt;{ block }]"
     :style="buttonStyle"
     @click="$emit('click')"&amp;gt;
     &lt;span class="nt"&gt;&amp;lt;slot&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;[...]&lt;/span&gt;
  &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&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="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;gray&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;

  &lt;span class="nx"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&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="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;buttonStyle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;computed&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="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will, of course, break any instance in which you had used the Button component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Handling Component Versions
&lt;/h3&gt;

&lt;p&gt;Approaching this problem, the most straightforward solution is to create a stopgap between the code of the component, and how the component is called.&lt;/p&gt;

&lt;p&gt;In this mindset then, we'll create a &lt;strong&gt;shell&lt;/strong&gt; component that'll wrap around &lt;strong&gt;versioned&lt;/strong&gt; components.&lt;/p&gt;

&lt;p&gt;Most likely you're used to organizing your components as such:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
   components/
      VButton.vue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which is probably useful in almost every scenario, but if you've happened to come across &lt;a href="https://theroadtoenterprise.com/"&gt;Vue - The Road to Enterprise by Thomas Findlay&lt;/a&gt; (which I highly recommend if you're beginning to architect large scale Vue apps), then you'll know that organizing Vue components is vital for a digestible code base.&lt;/p&gt;

&lt;p&gt;Borrowing a few concepts from Thomas, this is a good organizational strategy to handle component versioning:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
   components/
      global/
         VButton/
            index.vue   &amp;lt;-- shell
            VButton-v1.vue   &amp;lt;-- versioned
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will help keep your components nice and tidy, and with folders collapsed, the various component folders will provide easy reference for the grouping of shell and versioned components inside.&lt;/p&gt;

&lt;h4&gt;
  
  
  Writing a Shell Component
&lt;/h4&gt;

&lt;p&gt;For the sake of this Button component, and most likely all simple components, there's going to be 4 main things we have to handle when building a shell:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Passing props&lt;/li&gt;
&lt;li&gt;Passing attrs&lt;/li&gt;
&lt;li&gt;Carrying emits&lt;/li&gt;
&lt;li&gt;Passing slots&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;But first is how to handle the loading of the versioned component file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;component&lt;/span&gt; &lt;span class="na"&gt;:is=&lt;/span&gt;&lt;span class="s"&gt;"buttonComponent"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Button
  &lt;span class="nt"&gt;&amp;lt;/component&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;defineAsyncComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;defineComponent&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@nuxtjs/composition-api&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;defineComponent&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;VButton&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;version&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="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;v1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;

  &lt;span class="nx"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&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;versionComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;version&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;defineAsyncComponent&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="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`./VButton-&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;version&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.vue`&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="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;buttonComponent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;versionComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;version&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="p"&gt;})&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thanks to old tried and true &lt;code&gt;&amp;lt;component&amp;gt;&lt;/code&gt; paired with Vue3's &lt;code&gt;defineAsyncComponent&lt;/code&gt; this was actually a fairly easy lift.&lt;/p&gt;

&lt;p&gt;Next is handling props, attrs, and emits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;component&lt;/span&gt;
    &lt;span class="na"&gt;v-bind=&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;{ ...$attrs, ...$props }"
    :is="nButtonComponent"
    @click="$emit('click')"&amp;gt;
    Button
  &lt;span class="nt"&gt;&amp;lt;/component&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using built-in elements &lt;code&gt;$attrs&lt;/code&gt; and &lt;code&gt;$props&lt;/code&gt;, attrs and props are very easily passed to a child component to be digested.&lt;/p&gt;

&lt;p&gt;And lastly, slots:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;component&lt;/span&gt;
    &lt;span class="na"&gt;v-bind=&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;{ ...$attrs, ...$props }"
    :is="nButtonComponent"
    @click="$emit('click')"&amp;gt;
    &lt;span class="nt"&gt;&amp;lt;slot&lt;/span&gt;
      &lt;span class="na"&gt;v-for=&lt;/span&gt;&lt;span class="s"&gt;"(_, name) in $slots"&lt;/span&gt;
      &lt;span class="na"&gt;:name=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;
      &lt;span class="na"&gt;:slot=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/component&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The one flaw with using &lt;code&gt;$slots&lt;/code&gt; is that they're not dynamic, but this mostly gets the job done. Since each shell is specific to each component then it would be easy to more explicitly define slots if need be.&lt;/p&gt;

&lt;p&gt;And that's it. It's easy as importing your component just as you might normally:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import VButton from '@/components/global/VButton&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;But then when you use the component, passing a version prop notifies the &lt;strong&gt;shell&lt;/strong&gt; which &lt;strong&gt;versioned&lt;/strong&gt; component to use, and that should help curtail many breakages and allow adoption of the change to be handled over time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;Button&lt;/span&gt;
  &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"purple"&lt;/span&gt;
  &lt;span class="na"&gt;version=&lt;/span&gt;&lt;span class="s"&gt;"v1"&lt;/span&gt;
  &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"handleClick"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  Click Me!
&lt;span class="nt"&gt;&amp;lt;/Button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note:&lt;/em&gt; This is an MVP for this concept. Someone can rightly criticize this approach for some of the following reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It's not globally useable&lt;/li&gt;
&lt;li&gt;It could be much strong written in pure Vue3 render functions (this example comes from a Nuxt 2.15 app using the nuxtjs/composition-api plugin, which is missing some features from Vue3, including &lt;code&gt;resolveComponent&lt;/code&gt; which would most likely be able to solve this issue)&lt;/li&gt;
&lt;li&gt;This wouldn't be useful for more complex components&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While these are true, I still think this is a very useful strategy especially if you are the type of dev who builds their own UI from scratch.&lt;/p&gt;

&lt;h3&gt;
  
  
  Update
&lt;/h3&gt;

&lt;p&gt;After a bit of messing out on codesandbox, I put together a working example that also uses the render function as the &lt;strong&gt;shell&lt;/strong&gt; component:&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/intelligent-hill-iehm3"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note:&lt;/em&gt; In this Vue3 example &lt;code&gt;slots&lt;/code&gt; can just be directly passed as the third parameter, but in Nuxt (and possibly Vue2 with the composition-api plugin) it needs to be: &lt;code&gt;map(slots, slot =&amp;gt; slot)&lt;/code&gt; using lodash.&lt;/p&gt;

&lt;h3&gt;
  
  
  Update 2
&lt;/h3&gt;

&lt;p&gt;After working with the concept for a bit I hit a particular tricky spot - emits.&lt;/p&gt;

&lt;p&gt;The issue with emits is that, to my knowledge, there isn't a way to handle a passthrough of them as directly as you are able to with props or attributes.&lt;/p&gt;

&lt;p&gt;This makes the shell component a bit less "user friendly" because each shell becomes more customized, and forces there to be two components that need to have emits maintained.&lt;/p&gt;

&lt;p&gt;This is not optimal.&lt;/p&gt;

&lt;p&gt;Then I remembered an article I read about an anti-pattern in Vue, but a common one in React, passing functions as props (I wish I could find the article to link to it).&lt;/p&gt;

&lt;p&gt;Rather then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@click="$emit('myFunction', value)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@click="myFunction(value)"

// in &amp;lt;script&amp;gt;
props: {
  myFunction: Function
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I will say that this strategy is helpful on high-level components, but very low level components, like a button or input wrapper, would probably still be best served using emits in two places so that their events are easily consumed.&lt;/p&gt;

</description>
      <category>vue</category>
      <category>tutorial</category>
      <category>coding</category>
      <category>development</category>
    </item>
    <item>
      <title>Using Nuxt's New @nuxt/content Module To Launch My New Portfolio</title>
      <dc:creator>Ricardo Delgado</dc:creator>
      <pubDate>Wed, 02 Sep 2020 22:29:37 +0000</pubDate>
      <link>https://dev.to/rdelga80/using-nuxt-s-new-nuxt-content-module-to-launch-my-new-portfolio-3iha</link>
      <guid>https://dev.to/rdelga80/using-nuxt-s-new-nuxt-content-module-to-launch-my-new-portfolio-3iha</guid>
      <description>&lt;p&gt;It was about time I spruced up the old portfolio website, and the timing was perfect as it lined up with Nuxt introducing a new content generation module - &lt;a href="https://content.nuxtjs.org/"&gt;@nuxt/content module&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding Content To A Nuxt Project
&lt;/h3&gt;

&lt;p&gt;The setup for the &lt;code&gt;@nuxt/content&lt;/code&gt; is the same as any other new nuxt project. I prefer using:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn create nuxt-app &amp;lt;project-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then you can add the module:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn add @nuxt/content&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And in your &lt;em&gt;nuxt.config.js&lt;/em&gt; file add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="err"&gt;modules:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;'@nuxt/content'&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally, you'll want to make sure your Nuxt app is set to &lt;code&gt;universal&lt;/code&gt; to have access to &lt;code&gt;asyncData&lt;/code&gt;, and I'm using &lt;code&gt;static&lt;/code&gt; page generation.&lt;/p&gt;

&lt;p&gt;And that's it for the heavy lifting. This level of simplicity makes it quick and easy to get to the fun part and create your site.&lt;/p&gt;

&lt;p&gt;In your nuxt project, you'll now have a new folder called &lt;code&gt;content&lt;/code&gt;, and within that folder you'll be storing all your posts. I'm going with markdown but there's any number of different file types that Nuxt content can parse including &lt;code&gt;yaml&lt;/code&gt;, &lt;code&gt;yml&lt;/code&gt;, &lt;code&gt;csv&lt;/code&gt;, &lt;code&gt;json&lt;/code&gt;, &lt;code&gt;json5&lt;/code&gt;, &lt;code&gt;xml&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Each file has a front matter area, which is similar to &lt;a href="https://dev.to/"&gt;dev.to&lt;/a&gt;'s input area:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;--------
title: Title
description: Add a description
--------
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Along with built-in properties &lt;code&gt;dir&lt;/code&gt;, &lt;code&gt;path&lt;/code&gt;, &lt;code&gt;slug&lt;/code&gt;, &lt;code&gt;extension (ex: .md)&lt;/code&gt;, &lt;code&gt;createdAt&lt;/code&gt;, &lt;code&gt;updatedAt&lt;/code&gt;, you can also add custom ones, such as tags, which can be used to query content.&lt;/p&gt;

&lt;h3&gt;
  
  
  File Structure
&lt;/h3&gt;

&lt;p&gt;Next you'll want to create your file structure to handle loading your pages correctly.&lt;/p&gt;

&lt;p&gt;First thing, in the content folder I'm adding a sub-folder for just &lt;code&gt;articles&lt;/code&gt;, just in case in the future I want to have another content type available for use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- content
  + articles
    - new-articles.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then in the &lt;code&gt;pages&lt;/code&gt; directory I'm going to add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- pages
  + articles
    - _slug.vue
    - index.vue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that I'm going to leverage Nuxt's built in routing to create a page that accepts the slug as the path name, which is the article's file name. This will help long term with SEO, so make sure you're naming your files with that in mind.&lt;/p&gt;

&lt;h3&gt;
  
  
  Retrieving Content
&lt;/h3&gt;

&lt;p&gt;This is where things get really fun.&lt;/p&gt;

&lt;p&gt;The power of the Content module is that it adds &lt;code&gt;$content&lt;/code&gt; to the context.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$content&lt;/code&gt; is the built-in plugin that allows you to reach files within the content folder.&lt;/p&gt;

&lt;p&gt;Basic usage:&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="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;asyncData&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;$content&lt;/span&gt; &lt;span class="p"&gt;})&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;docs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;$content&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;articles&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;docs&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, &lt;code&gt;$content&lt;/code&gt; receives two-ish parameters, the first is the path within the content folder, the second are options. The reason I say two-ish parameters is because as you add parameters to the beginning of the call to create a specific file path.&lt;/p&gt;

&lt;p&gt;Also, note the use of &lt;code&gt;asyncData&lt;/code&gt; in this example and within the docs. Something to keep in mind is that &lt;code&gt;asyncData&lt;/code&gt; is only accessible to files within the pages folder, otherwise if you wanted to use it in another area, such as in a component, you'd have to use the &lt;code&gt;beforeMount&lt;/code&gt; lifecycle hook using &lt;code&gt;this.$content&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Displaying Content
&lt;/h3&gt;

&lt;p&gt;Another handy bit of functionality that comes with the module is the &lt;code&gt;&amp;lt;nuxt-content&amp;gt;&lt;/code&gt; component.&lt;/p&gt;

&lt;p&gt;Basically, it accepts the returned content from &lt;code&gt;asyncData&lt;/code&gt; and displays it without any handling.&lt;/p&gt;

&lt;p&gt;From the above example, since we returned an array of articles, then your template would look something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;nuxt-content&lt;/span&gt;
  &lt;span class="na"&gt;v-for=&lt;/span&gt;&lt;span class="s"&gt;"doc in docs"&lt;/span&gt;
  &lt;span class="na"&gt;:document=&lt;/span&gt;&lt;span class="s"&gt;"doc"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it! Everything translated properly from your content files beautifully on the page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Leveraging Content
&lt;/h3&gt;

&lt;p&gt;While a lot of cases will be handled with the basic usage of &lt;code&gt;$content&lt;/code&gt; here's just a couple of examples on some more things you can do with the content module.&lt;/p&gt;

&lt;h4&gt;
  
  
  Accessing a specific article
&lt;/h4&gt;

&lt;p&gt;Since the content path spreads, you can use &lt;code&gt;$content&lt;/code&gt; coupled with another context element &lt;code&gt;$params&lt;/code&gt; to retrieve specific articles.&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="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;asyncData&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;$content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="p"&gt;})&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;doc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;$content&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;articles&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;index&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;doc&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows for an incredibly clean and SEO friendly way to share posts and articles.&lt;/p&gt;

&lt;h4&gt;
  
  
  Creating an articles index page
&lt;/h4&gt;

&lt;p&gt;Some of the other functionalities of &lt;code&gt;$content&lt;/code&gt; are focused around querying your content files.&lt;/p&gt;

&lt;p&gt;Some examples are &lt;code&gt;only&lt;/code&gt;, &lt;code&gt;sortBy&lt;/code&gt;, and &lt;code&gt;limit&lt;/code&gt;, but you can find the complete method listings here: &lt;a href="https://content.nuxtjs.org/fetching"&gt;https://content.nuxtjs.org/fetching&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create an articles index page, we're going to aim for a few specific criteria:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Limited to 5 posts&lt;/li&gt;
&lt;li&gt;Shows only the header, the date, and the description&lt;/li&gt;
&lt;li&gt;Sort by most recent&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To accomplish this we can do 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="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;asyncData&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;$content&lt;/span&gt; &lt;span class="p"&gt;})&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;articles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;$content&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;articles&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;only&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;createdAt&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;description&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sortBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;createdAt&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;desc&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;articles&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then in your template, you can specifically handle the various items:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;v-for=&lt;/span&gt;&lt;span class="s"&gt;"article in articles"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;{{ article.title }}&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;{{ article.description }}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;small&amp;gt;&lt;/span&gt;{{ article.createdAt }}&lt;span class="nt"&gt;&amp;lt;/small&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple as that.&lt;/p&gt;

&lt;p&gt;While using the content module can create simple websites incredibly easily, I can envision some enterprise uses as well.&lt;/p&gt;

&lt;p&gt;Looking forward to diving even deeper into @nuxt/content.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This article is cross posted from &lt;a href="https://ricdelgado.com/articles/nuxt-content-new-site"&gt;https://ricdelgado.com/articles/nuxt-content-new-site&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>nuxt</category>
      <category>content</category>
      <category>blog</category>
      <category>vue</category>
    </item>
    <item>
      <title>Mocking Nuxt Global Plugins to Test a Vuex Store File</title>
      <dc:creator>Ricardo Delgado</dc:creator>
      <pubDate>Wed, 06 May 2020 20:47:31 +0000</pubDate>
      <link>https://dev.to/rdelga80/mocking-nuxt-global-plugins-to-test-a-vuex-store-file-45e6</link>
      <guid>https://dev.to/rdelga80/mocking-nuxt-global-plugins-to-test-a-vuex-store-file-45e6</guid>
      <description>&lt;p&gt;This is one of those edge cases that drives a developer up the wall, and once it's finally solved you run to The Practical Dev to hopefully spare someone else the pain you went through.&lt;/p&gt;

&lt;p&gt;I've written previously about Vue Testing: &lt;a href="https://dev.to/rdelga80/vuejs-testing-what-not-how-hn4"&gt;VueJS Testing: What Not How&lt;/a&gt;, and since then have become the "go-to" for my company's Vue testing issues.&lt;/p&gt;

&lt;p&gt;But this one was quite a head scratcher.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Problem
&lt;/h3&gt;

&lt;p&gt;Vue's testing is pretty straight forward thanks to &lt;code&gt;vue-test-utils&lt;/code&gt;. Testing components is really easy, as long as pieces are properly broken down to units (see my post).&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;vue-test-utils&lt;/code&gt; you can mount components locally within the test file, test against the local mount, and ta-da tests.&lt;/p&gt;

&lt;p&gt;Via the mount, and Jest's functionality, things like plugins and mocks can be handled either locally within the file or globally within config or mock files.&lt;/p&gt;

&lt;p&gt;This problem, though, has to deal with Vuex Store files which &lt;em&gt;are not mounted&lt;/em&gt;. This is because state, actions, mutations, and getters are tested directly and not within the Vue ecosystem (which behave differently than if tested directly).&lt;/p&gt;

&lt;p&gt;Sample Vuex Store file:&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;actions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;testAction&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;commit&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;TEST_MUTATION&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mutations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;TEST_MUTATIONS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sample Vuex Store test file:&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;cloneDeep&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lodash-es&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;testStore&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@/store/testFile&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@/store/testFile&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&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;let&lt;/span&gt; &lt;span class="nx"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nx"&gt;mutations&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cloneStore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cloneDeep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;testStore&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="nx"&gt;beforeEach&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="nx"&gt;actions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cloneStore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;actions&lt;/span&gt;
        &lt;span class="nx"&gt;mutations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cloneStore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mutations&lt;/span&gt;
    &lt;span class="p"&gt;)}&lt;/span&gt;

    &lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;test action calls test mutation&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&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="nx"&gt;commit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;jest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="nx"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;testActions&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;commit&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;

        &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toHaveBeenCalledWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;TEST_MUTATION&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;anything&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Approaches
&lt;/h3&gt;

&lt;p&gt;This issue circled around a global plugin called &lt;code&gt;$plugin&lt;/code&gt;, which is a plugin that was created to handle api requests globally.&lt;/p&gt;

&lt;p&gt;This means that within the store file there is no imported module, and therefore rules out solutions such as &lt;code&gt;jest.mock()&lt;/code&gt; or adding a file to the &lt;code&gt;__mocks__&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;This also ruled out adding to &lt;code&gt;VueTestUtils.config&lt;/code&gt;, since again there is no Vue instance to test against.&lt;/p&gt;

&lt;p&gt;Every time the test was run it returned &lt;code&gt;$plugin&lt;/code&gt; as being undefined.&lt;/p&gt;

&lt;h3&gt;
  
  
  Solution
&lt;/h3&gt;

&lt;p&gt;The solution to this problem is actually pretty easy, and I'm a little surprised it took so long to figure out.&lt;/p&gt;

&lt;p&gt;Here's an example of what an action like this may look like:&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;actions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;testAction&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;commit&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$plugin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`endpoint`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SET_DATA&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When imported into a test file, it acts as a pure function, without having anything to do with Vuex functionality.&lt;/p&gt;

&lt;p&gt;That means that &lt;code&gt;this&lt;/code&gt; refers to the actions variable, and not a Vue instance!&lt;/p&gt;

&lt;p&gt;Once that was cleared up, I added this to the &lt;code&gt;beforeEach&lt;/code&gt; loop in the test file:&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="nx"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$plugin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;list&lt;/span&gt;&lt;span class="p"&gt;:&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="p"&gt;[{}]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's all. No more failing tests, and no more undefined plugins.&lt;/p&gt;

</description>
      <category>vue</category>
      <category>testing</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Appreciating The Iteration</title>
      <dc:creator>Ricardo Delgado</dc:creator>
      <pubDate>Mon, 27 Jan 2020 12:56:53 +0000</pubDate>
      <link>https://dev.to/rdelga80/appreciating-the-iteration-3587</link>
      <guid>https://dev.to/rdelga80/appreciating-the-iteration-3587</guid>
      <description>&lt;p&gt;Software Engineering is a modern day dilemma akin to Don Quixote charging at windmills in attempts to slay dragons.&lt;/p&gt;

&lt;p&gt;It's miraculous to watch people in a team spend hours upon hours discussing solutions for problems that are as easy to reach as sending the Space Shuttle to Proxima Centauri.&lt;/p&gt;

&lt;p&gt;It's the moment when the title Engineer is most obvious, mentally walking down branches, attempting to avoid future pitfalls for solutions that haven't even been implemented.&lt;/p&gt;

&lt;p&gt;Internally, the Engineering mind is quite fun and exciting, yet a boiling cauldron of contradictory realities of insecurity and deep set assuredness.&lt;/p&gt;

&lt;p&gt;One of the hardest issues that I've faced in my short time as a professional Front-end Developer is accepting that my job is one that can't give me a sense of daily accomplishment in return for a full day of writing code.&lt;/p&gt;

&lt;p&gt;All arrows are pointing to completion, finishing the task, launching a product, meeting timelines, and not disappointing users and bosses alike.&lt;/p&gt;

&lt;p&gt;I'm grateful for the company I work for, because they're acutely aware of Developer burnout and push hard for us not to cross 40 hours of work per week.&lt;/p&gt;

&lt;p&gt;Nonetheless, the opposing force of "finishing a product" pushes back hard, and I cannot deny that as a deadline begins to approach, the pressure mounts no matter how hard you may be told not to let it.&lt;/p&gt;

&lt;p&gt;These are how the seeds of stress are planted. It's how coding standards and a programmer's well-being are put aside for the sake of meeting an artificial line drawn in the sand. All to be able to click a checkbox to move a project from version 1 to version 1.1?&lt;/p&gt;

&lt;p&gt;These things don't do much to motivate.&lt;/p&gt;

&lt;p&gt;To me there's nothing better than the act of creation and making it work. The dopamine hit of seeing a problem and solving it, which may or may not align with administrative goals in project estimation.&lt;/p&gt;

&lt;p&gt;How then can an engineer maintain a sense of completion in workflows that are &lt;em&gt;never&lt;/em&gt; complete?&lt;/p&gt;

&lt;p&gt;This is so hard to mentally understand as the most obvious signs are pointing towards finality and accomplishment. As we lust over that moment we can put down our tools, kick our heels up, and say to ourselves, "ah ha, this is just how I wanted it."&lt;/p&gt;

&lt;p&gt;That dream is impossible, and chasing these ghosts of our imagination can drive someone mad.&lt;/p&gt;

&lt;p&gt;Leaving these aside, what measure can be used to feel our way through a workday? If far off goals leave you feeling empty and unaccomplished, how can someone maintain a perspective to avoid falling for the pitfall of "completion"?&lt;/p&gt;

&lt;p&gt;Take yourself back to your first code camps. Or the first coding lessons you took. Or the first time you wrote actual code.&lt;/p&gt;

&lt;p&gt;Think back to the first time you figured out how to use a loop, manipulate data, move an UI element with the click of a button? Whatever those early senses of achievement may have been.&lt;/p&gt;

&lt;p&gt;Knowledge is a powerful drug, as well as a destroyer of the simplicity.&lt;/p&gt;

&lt;p&gt;But that doesn't mean that the simple excitement of basic accomplishment is &lt;em&gt;gone&lt;/em&gt;, it just means that you stopped paying attention to it in lieu of something you believe to be more compelling.&lt;/p&gt;

&lt;p&gt;Allowing the mind to keep searching for more and more complex problems to solve may be the foundation of your pay rate, but unfortunately leaves the beauty of the mundane by the wayside, a tragedy to chasing achievement.&lt;/p&gt;

&lt;p&gt;If feeling lost and bored while developing, and stressed at far off goals, allow for a challenge to bring things back to basics.&lt;/p&gt;

&lt;p&gt;Bring your attention back to the moment by moment pleasure that you feel by solving problems, breaking down a puzzle, and connecting with fellow like-minded people who are driving towards accomplishing something together.&lt;/p&gt;

&lt;p&gt;Leave behind the wide-viewed problems, and find your way back to the smallest of accomplishments.&lt;/p&gt;

&lt;p&gt;Then iterate it. Again and again and again.&lt;/p&gt;

&lt;p&gt;Placing emotional payoffs in small, everyday accomplishments will quickly make far off, nearly unachievable focuses seem silly.&lt;/p&gt;

&lt;p&gt;By the time a goal, artificial or not, is reached, you've had hundreds upon hundreds of little victories. You won't be worried about putting things down to take a break after "accomplishing something so huge," you'll be excited about tomorrow's fun and excitement for a whole new set of accomplishments to achieve.&lt;/p&gt;

&lt;p&gt;Ultimately, you and your mental well-being are more important than any product that could be made - sacrificing that for any reason will do nothing more than keep any long-term goal from being accomplished anyway. &lt;/p&gt;

&lt;p&gt;And why sacrifice both to accomplish neither?&lt;/p&gt;

</description>
      <category>career</category>
      <category>webdev</category>
      <category>productivity</category>
      <category>psychology</category>
    </item>
    <item>
      <title>Rebuilding A BBS Relic</title>
      <dc:creator>Ricardo Delgado</dc:creator>
      <pubDate>Sun, 19 Jan 2020 14:42:05 +0000</pubDate>
      <link>https://dev.to/rdelga80/rebuilding-a-bbs-relic-37j</link>
      <guid>https://dev.to/rdelga80/rebuilding-a-bbs-relic-37j</guid>
      <description>&lt;p&gt;I'm reaching that point in my life where I get to shake my fist at the clouds, and yell at these young whippersnappers about how much better online gaming used to be in a time before the internet.&lt;/p&gt;

&lt;p&gt;What's this oxymoronic sentence I wrote, you may be asking? Online gaming &lt;em&gt;before&lt;/em&gt; the internet?&lt;/p&gt;

&lt;p&gt;That's right kids, there indeed was a moment in computer history pulling together the two separate moments of playing chess against a 16-bit Intel 8086 Processor and neverending worlds of Orc battles.&lt;/p&gt;

&lt;p&gt;You may or may not be familiar with this sound:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/gsNaR6FRuO0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;But this was the sound of pure online communities. It wasn't to connect with people from around the world, but rather other nerds in your neighborhood.&lt;/p&gt;

&lt;p&gt;It's hard to imagine, but Bulletin Board Systems (BBS) formed in a time before being a nerd was cool. When being too smart or being different meant that you'd actually be a societal outcast.&lt;/p&gt;

&lt;p&gt;BBS were one of the rare places where refuge could be found amount like-minded weirdos, and of course one of the first aspects to grow out of the new communities was robust gaming community.&lt;/p&gt;

&lt;p&gt;Captured in AMC's now defunct tech-drama "Halt and Catch Fire", the rise of BBS, preceding the browser wars of the early-to-mid-90s, was something that could be compared to the childhood of the internet: naive and innocent.&lt;/p&gt;

&lt;p&gt;It's still my favorite time of my personal history dealing with computers.&lt;/p&gt;

&lt;p&gt;And since I'm hitting my nostalgic years, I thought it was about time to revisit one of my favorite BBS games - &lt;strong&gt;&lt;em&gt;Barren Realms Elite&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Barren Realms Elite was a turn based strategy game, where you would make various decisions around war, banking, land use, etc., to defeat other people in the game.&lt;/p&gt;

&lt;p&gt;While that was fun in and of itself, what I miss the most is playing a game where you only get &lt;em&gt;one turn per day&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rebuilding Barren Realms Elite
&lt;/h3&gt;

&lt;p&gt;The original BRE, which was based on an earlier version called Solar Realms Elite, and developed by Amit Patel can be found here: &lt;a href="http://www-cs-students.stanford.edu/~amitp/Articles/SRE-Documentation.html" rel="noopener noreferrer"&gt;http://www-cs-students.stanford.edu/~amitp/Articles/SRE-Documentation.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There's also some online BBS modulators where you can plan the original version as well: &lt;a href="https://archive.org/details/msdos_Barren_Realms_Elite_1999" rel="noopener noreferrer"&gt;https://archive.org/details/msdos_Barren_Realms_Elite_1999&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What was done is amazing, and it'll be the foundation for my new project:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LORD DYSTOPIA&lt;/strong&gt;&lt;/p&gt;

&lt;p&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%2Fdx75lbp143zi4bzrbql0.png" 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%2Fdx75lbp143zi4bzrbql0.png" alt="Lord Dystopia"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To keep things simple, I'll be developing the game in NuxtJS (VueJS), with a Firebase backend. Before there is any comments "why build it with that" - it's what I know best and can develop in the fastest.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Lord Dystopia&lt;/em&gt; will share many of the same features such as warring, trading, covert operations, and land usage.&lt;/p&gt;

&lt;p&gt;Games will be up to 25 players, and will have a length of 1 month, with point totals being determined by troop totals, food, land, money, and some other factors with the winner having the highest point totals at the end of that month.&lt;/p&gt;

&lt;p&gt;Most importantly, though, is that each player will only have one opportunity per day to take up to 5 turns.&lt;/p&gt;

&lt;p&gt;Thankfully there won't be much, if any, need for visual aspects and I can focus on game play and functionality.&lt;/p&gt;

&lt;p&gt;I want to state upfront that this is a fun project that I'm choosing to work on for nothing more than a love of programming and missing a game I used to love playing.&lt;/p&gt;

&lt;p&gt;If you're interested in signing up to be a BETA tester, please send an email to: &lt;a href="mailto:lorddystopiaonline@gmail.com"&gt;lorddystopiaonline@gmail.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks! Look forward to seeing you on the battlefield.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>fun</category>
      <category>sideprojects</category>
      <category>vue</category>
    </item>
    <item>
      <title>Cultivating A Positive Attitude To Be A Better Dev</title>
      <dc:creator>Ricardo Delgado</dc:creator>
      <pubDate>Fri, 08 Nov 2019 14:00:40 +0000</pubDate>
      <link>https://dev.to/rdelga80/cultivating-a-positive-attitude-to-be-a-better-dev-3bai</link>
      <guid>https://dev.to/rdelga80/cultivating-a-positive-attitude-to-be-a-better-dev-3bai</guid>
      <description>&lt;p&gt;The interconnectedness of building products demands that even the most technical roles requires you to be a pleasant coworker for the sake of your team.&lt;/p&gt;

&lt;p&gt;While in theory that seems like great advice, the details are easily lost, especially to people who tend to be naturally introverted and don't have naturally strong skills in social dynamics.&lt;/p&gt;

&lt;p&gt;I'm writing this post on DEV in the lens of making your workplace an easier situation to exist in, but this mentality easily extends beyond that. Whether it's family, friends, neighbors, new situations, or anything where it's required for you to get along with others, a positive attitude will benefit you in unimaginable ways.&lt;/p&gt;

&lt;h2&gt;
  
  
  People Like Happy People
&lt;/h2&gt;

&lt;p&gt;There's going to be a strange underlying sentiment behind this post - "should I act this way to make other people like me, or should I do it to feel better in my life?"&lt;/p&gt;

&lt;p&gt;This is a very valid question, and truthfully there's no set answer.&lt;/p&gt;

&lt;p&gt;Personally, I'm a bit rebellious, grew up listening to punk rock, and generally don't mind pissing people off. One time in college someone told me they'd never seen me smile, and truthfully I think I would've been able to live my entire life rarely leaving my apartment unless it was necessary.&lt;/p&gt;

&lt;p&gt;But, that attitude didn't do anything in terms of progressing my life, and especially made it difficult for me to deal with other people.&lt;/p&gt;

&lt;p&gt;School, work, friendships, family... most of these situations were a living hell for me.&lt;/p&gt;

&lt;p&gt;If there were other people involved, there would always be some kind of drama or conflict.&lt;/p&gt;

&lt;p&gt;For me learning how to cultivate a positive attitude not only made my normal interactions better, and helped get me my current position as a software engineer despite not having professional experience (and I've been informed my attitude is a reason why), but it's made my daily life feel so much better.&lt;/p&gt;

&lt;p&gt;There's no Sophie's Choice. Whatever your motivations may be, cultivating a positive attitude will improve your life in a multitude of ways, including workplace success.&lt;/p&gt;

&lt;h2&gt;
  
  
  Worrying Too Much About Others
&lt;/h2&gt;

&lt;p&gt;When I made my first leaps into changing my life outlook, I realized that I was constantly looking at the things other people did and judged it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"Why did that guy make that wrong turn? What an idiot!"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"Why would someone leave this here? That's so inconsiderate!"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"Who would say something like that? They must be a selfish jerk!"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"My boss said something rude! He's totally incompetent!"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;And are any of these statements wrong? Probably not.&lt;/p&gt;

&lt;p&gt;The problem is the sphere of your attention and focus, and how it undermines your ability to be in control of your circumstances.&lt;/p&gt;

&lt;p&gt;Accept this upfront - &lt;strong&gt;there is no perfect world in which you can currently live in.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The fact is that no matter how much you complain, get upset, honk your horn, or yell at your tv, you will never be able to change the way other people behave.&lt;/p&gt;

&lt;p&gt;This doesn't mean that you should become a mat that people can walk over and abuse. But allow your focus to peel off from &lt;em&gt;them&lt;/em&gt; and return to you.&lt;/p&gt;

&lt;p&gt;Ultimately, I think there's two subconscious self-destructive mechanisms at work:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You're disappointed in the world you see around you. It hurts deeply when they don't ascend to your expectations of excellence, and&lt;/li&gt;
&lt;li&gt;You aren't deserving of your own attention, and it going to others is a way that you punish yourself by not allowing yourself to feel good about you and your life.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is normal. Most people live inside of this world. Don't beat yourself up about it.&lt;/p&gt;

&lt;p&gt;But, I will turn it around and say, how many times have you messed something up in your life? Be it minor, like making a wrong turn, or not carefully watching what you say.&lt;/p&gt;

&lt;p&gt;Let's say it happens 3 times a week.&lt;/p&gt;

&lt;p&gt;Now think about how many people you cross paths with on a daily basis. And it may be possible you may have witnessed one person, out of the thousands you may come by, do one of their 3 screwups.&lt;/p&gt;

&lt;h2&gt;
  
  
  Assuming The Best In People
&lt;/h2&gt;

&lt;p&gt;A lot of the issues that arise around dealing with people is the assumption that you know their intentions.&lt;/p&gt;

&lt;p&gt;Unfortunately, the human mind hasn't evolved the ability to mind reading yet, and if anything recent studies show that people are terrible at understanding each other's intentions.&lt;/p&gt;

&lt;p&gt;Often times when dealing with other's, especially in the work environment, there's an unfortunately thick layer of suspicion and defensiveness.&lt;/p&gt;

&lt;p&gt;There's a strong desire, for example, to always interpret your boss's directions as a criticism of your work.&lt;/p&gt;

&lt;p&gt;Leading to: &lt;em&gt;"why would they say that? Why would they do those things? Don't they know I'm working hard?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When, in reality, your boss may actually have something in mind that you don't know or aren't privy to. Or, even better, they're truly trying to help you become a better worker.&lt;/p&gt;

&lt;p&gt;Of course, on the other hand, you may have a sociopath as an employer. I've had a few myself. Every critique was actually a power move on their part, trying to demean me for their own ego inflation.&lt;/p&gt;

&lt;p&gt;The problem is that even in those worst of circumstances, people have nowhere near the amount of introspection to realize that they're doing unfair actions towards a subordinate. To them its justified management.&lt;/p&gt;

&lt;p&gt;The question again boils down to measure of control.&lt;/p&gt;

&lt;p&gt;Even at the two ends of the spectrum, assuming people's best intentions solves both scenarios.&lt;/p&gt;

&lt;p&gt;As an employee, if you take direction and assume that it comes from the best place, you will be thankful and appreciative that your boss is concerned about you doing the best work you can.&lt;/p&gt;

&lt;p&gt;Even if their intentions are not fully wholesome, you at least will placate their issues and most likely will leave you alone because you're not giving them the pushback they're looking for.&lt;/p&gt;

&lt;p&gt;Of course, if you do have a sociopathic boss, &lt;em&gt;please&lt;/em&gt; go looking for a new job - it'll especially be much easier to find one with a new positive attitude!&lt;/p&gt;

&lt;h2&gt;
  
  
  Practical Steps
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Positive Affirmations
&lt;/h3&gt;

&lt;p&gt;Positive affirmations are more commonly known as "fake it till you make it," and are one of the most powerful ways of improving your mentality.&lt;/p&gt;

&lt;p&gt;First, take a sheet of paper, fold it in half, and write down 5 to 10 negative self-thoughts or beliefs you hold on the left side.&lt;/p&gt;

&lt;p&gt;On the right side write the positive take on the negative side, being careful not to state it negatively.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Negative: I am not a hard worker&lt;/li&gt;
&lt;li&gt;Positive: I enjoy taking my time with work, and don't put unrealistic demands on myself&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A less effective positive spin would be something like: I am a hard worker.&lt;/p&gt;

&lt;p&gt;The key is not to lie to yourself, but to instead change your thoughts from negative to positive. While what you're focusing on specifically is important in a certain way, it's more a matter of redirecting the internal process and voice inside your head.&lt;/p&gt;

&lt;p&gt;After you've created a list of 5 to 10 affirmations, tear them away from the other side of the paper, and now you have a list of things to repeat yourself daily.&lt;/p&gt;

&lt;p&gt;Maybe post them on your bathroom mirror, and repeat them to yourself. Or maybe on your fridge. Basically anywhere you'll remember to repeat them to yourself regularly.&lt;/p&gt;

&lt;p&gt;It's also important that when you feel the negative thought arise, you &lt;em&gt;gently&lt;/em&gt; guide them to the positive affirmation.&lt;/p&gt;

&lt;p&gt;It's vital not to see negative arising thoughts as bad or wrong, but rather a built in neurological connection between two points in your brain that you're trying to redirect somewhere else.&lt;/p&gt;

&lt;p&gt;Doing this regularly will create a more harmonious internal experience, which will then reflect to the world around you.&lt;/p&gt;

&lt;h3&gt;
  
  
  Daily Meditation
&lt;/h3&gt;

&lt;p&gt;I wrote last time about &lt;a href="https://dev.to/rdelga80/incorporating-meditation-into-your-programming-routine-132k"&gt;how to get started meditating&lt;/a&gt;, so I won't get too much into the mechanics.&lt;/p&gt;

&lt;p&gt;I wanted to focus on one main key that's a byproduct of meditating - &lt;em&gt;becoming less reactive.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Meditation, in part, is the act of constantly watching your thoughts from a distance. Reinforcing this feeling over and over again, eventually you learn how to keep a healthy distance from them, and don't react quite as quickly as you normally would.&lt;/p&gt;

&lt;p&gt;In a work setting this can be the difference between a healthy meeting, or an ugly one that turns personal.&lt;/p&gt;

&lt;p&gt;Being able to maintain distance from an arising thought like, "why would they say that?" in the middle of a high pressure situation that can happen in certain meetings, can save a lot of potential headaches.&lt;/p&gt;

&lt;p&gt;You'll find yourself acting more like a mediator between yourself and the external world, rather than a combatant.&lt;/p&gt;




&lt;p&gt;These are only a few small things that can help relieve a great deal of pressure that comes with the odd dynamics we find ourselves in because of work.&lt;/p&gt;

&lt;p&gt;Becoming more light-hearted, more present, less argumentative, more helpful, patient, and understanding can be hugely important in progressing in your career.&lt;/p&gt;

&lt;p&gt;But beyond that, it can also help greatly in your personal life. And that kind of benefit is worth investing time in.&lt;/p&gt;

&lt;p&gt;Some other great resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://thework.com/"&gt;The Work by Byron Katie&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/Power-Now-Guide-Spiritual-Enlightenment-ebook/dp/B002361MLA"&gt;The Power of Now by Eckhart Tolle&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/Four-Agreements-Practical-Personal-Freedom/dp/1878424319"&gt;The Four Agreements by Don Miguel Ruiz&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/Alchemist-Paulo-Coelho/dp/0062315005"&gt;The Alchemist by Paulo Cuelho&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>career</category>
      <category>productivity</category>
      <category>mindset</category>
      <category>selfcare</category>
    </item>
    <item>
      <title>Incorporating Meditation Into Your Programming Routine</title>
      <dc:creator>Ricardo Delgado</dc:creator>
      <pubDate>Mon, 28 Oct 2019 15:05:15 +0000</pubDate>
      <link>https://dev.to/rdelga80/incorporating-meditation-into-your-programming-routine-132k</link>
      <guid>https://dev.to/rdelga80/incorporating-meditation-into-your-programming-routine-132k</guid>
      <description>&lt;p&gt;It's easy to get lost in the specificity of a career in computer science.&lt;/p&gt;

&lt;p&gt;What's the right framework? Which language is the best? Mac vs Windows vs Linux? Tabs vs spaces?!&lt;/p&gt;

&lt;p&gt;Unfortunately, the surrounding foundation can sometimes be left untended. How good of a programmer can you really be if you're fraught with anxiety and depression? Or in a less dramatic way, unable to clear mental clutter while making decisions?&lt;/p&gt;

&lt;h2&gt;
  
  
  This is not a cure all
&lt;/h2&gt;

&lt;p&gt;Often in the meditation and spiritual communities, meditation is sold as a cure for all mental and physical issues.&lt;/p&gt;

&lt;p&gt;It's too easy to go to a "guru" and ask for help in a situation, and the response be "meditate more."&lt;/p&gt;

&lt;p&gt;Rather than that, I'd instead try to propose seeing meditation as a structure in which one can build stronger mental tools. While there are numerous personal benefits to it, for the sake of posting this on DEV, I'd rather focus on how meditation can improve your skills as an engineer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mental Clarity
&lt;/h3&gt;

&lt;p&gt;Without a doubt, a good meditation practice can clear out a great deal of the mental chatter that torments the inside of many people's minds.&lt;/p&gt;

&lt;p&gt;This includes negative self-talk, constant self-doubt, a layer of suspicious interpretation while communicating, and that general stream of internal voice that never seems to quiet when you want to focus on work.&lt;/p&gt;

&lt;p&gt;One of the most important lessons when learning meditation is that you are not your thoughts, a concept made most famous by self-help author Eckhart Tolle.&lt;/p&gt;

&lt;p&gt;As an industry founded on thinking this may be a hard pill to swallow, but to maybe loosen your assuredness, watch this video by Neuroscientist and meditation teacher Gary Weber about thoughts:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/WnWxCgiZfrc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In essence, quieting your thoughts and relaxing the feeling of ownership over problem solving (and seemingly "higher cognitive functions"), allows for smoother thinking.&lt;/p&gt;

&lt;h3&gt;
  
  
  Stress and Personal Relief
&lt;/h3&gt;

&lt;p&gt;While I don't want to focus on the de-stressing aspects of meditation too much, I will at least ask you if taking a small amount of time out of your day is worth providing a reduction in your stress?&lt;/p&gt;

&lt;p&gt;What if 10 minutes of meditation reduced your stress by 5%? Would that be worth it?&lt;/p&gt;

&lt;p&gt;What about 20 minutes, reducing 20%?&lt;/p&gt;

&lt;p&gt;It's just something to keep in mind. Again, this is not a cure-all, but it does help to focus on the fact that a small investment of time can have a noticeable, and not insignificant, return.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Very Beginner's Guide To Meditation
&lt;/h2&gt;

&lt;p&gt;It is more than possible to fully immerse yourself in all the various types of meditation practices, find yourself on a week long retreat, and be on the path to full blown enlightenment.&lt;/p&gt;

&lt;p&gt;These things are possible, and there are many people pursuing it and experiencing it everyday.&lt;/p&gt;

&lt;p&gt;But that does not need to be the goal of your practice. Technically anyone's practice can be whatever they'd like it to be - as long as it's &lt;strong&gt;wholesome&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this article I'll focus on a very basic concentration practice that only needs to last 10 to 15 minutes, and will have a good effect at relaxing the mind.&lt;/p&gt;

&lt;p&gt;While it's not required, I will add that personally I have experienced the benefits of moving beyond the beginner level of meditation. Some teachers, like Robert Thurman, would argue that solely doing concentration practice without diving into the deeper practices only achieves temporary gains, as opposed to the massive and life altering changes that happen with a more serious meditation practice.&lt;/p&gt;

&lt;p&gt;But for now, we'll happily take the temporary gains for the sake of career betterment.&lt;/p&gt;

&lt;h4&gt;
  
  
  Getting Started - What To Focus On
&lt;/h4&gt;

&lt;p&gt;Let me say this upfront, and I want you to hear this in your head as you get started - &lt;em&gt;you will never ever stop your thoughts as a beginning meditator&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;This is by far the loudest feedback I hear from people when they tell me that they've tried meditation but didn't continue their practice.&lt;/p&gt;

&lt;p&gt;"I stopped because I couldn't get my thoughts to stop."&lt;/p&gt;

&lt;p&gt;Let me reassure you, if you were a meditator for 10 years, and you managed to silence your thoughts, it would be seriously impressive.&lt;/p&gt;

&lt;p&gt;This is perhaps born from a Westerner's interpretation of what a process is about - focusing too much on the finish line while losing the joy of the action itself.&lt;/p&gt;

&lt;p&gt;Yes, you will have thoughts. Yes, they will drag you away from the nowness you're trying to achieve. Yes, it will be distracting and you can feel frustrated if you focus too much on "I didn't win this meditation round."&lt;/p&gt;

&lt;p&gt;There's two things to be aware of:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;This is a &lt;strong&gt;practice&lt;/strong&gt;. That means that how you go about it is how you will do it. If you make your practice relaxing and enjoyable, you are practicing relaxation and enjoyment. If your practice is frustrating and unpleasant, you are practicing frustration and unpleasantness. These things will carry into your life because you are practicing them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Even though "you are not your thoughts", you are also your thoughts.* And any frustration you push towards your thoughts, you're also pushing on yourself. This will have the opposite effect of relieving stress that you're trying to achieve. In the "you are not your thoughts" domain, try to give yourself direction, but don't be cruel, mean, or lacking sympathy to thoughts - as they are yourself in a way. Practice loving yourself and your mind and you will be more loving towards yourself and your mind.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;** &lt;em&gt;Note: If there's anything about spiritual and meditative practices you'll have to be comfortable with its contradictions. I apologize ahead of time to all the hyper-analytical thinkers.&lt;/em&gt;*&lt;/p&gt;

&lt;h4&gt;
  
  
  Sitting Form
&lt;/h4&gt;

&lt;p&gt;Let me be upfront - this kind of stuff doesn't matter much. Before listing out the traditional sitting positions, know that what's important is that you're comfortable enough to sit in one of these positions for long periods of time.&lt;/p&gt;

&lt;p&gt;Other than that, if you're sitting, it's about good posture. A long back, shoulders high, and stable posture are perfect. If you're laying down, maintain a position where you won't fall asleep (unless you're trying to fall asleep!).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Full Lotus&lt;/em&gt;&lt;/p&gt;

&lt;p&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%2Ftffd9uunhz78swk8v9rt.jpg" 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%2Ftffd9uunhz78swk8v9rt.jpg" alt="Full Lotus Seated Meditation Position"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each foot rests atop the thigh of the opposing leg. This is a very traditional position, but can be very tough on the knees and legs for people who haven't been practicing in this position from a young age.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Half Lotus&lt;/em&gt;&lt;/p&gt;

&lt;p&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%2Fb3tbqmau7jsqny6yepxm.jpg" 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%2Fb3tbqmau7jsqny6yepxm.jpg" alt="Half Lotus Seated Meditation Position"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is my preferred sitting position. One foot sits atop the other's thigh. Easier on the knees.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Seated&lt;/em&gt;&lt;/p&gt;

&lt;p&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%2F5s3fj0l3jvkpjao16f6h.jpg" 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%2F5s3fj0l3jvkpjao16f6h.jpg" alt="Seated Meditation Position"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The typical way Westerners sit. Totally ok for meditation, make sure to maintain good posture and relaxed arms.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Chair Sitting&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you are older or have physical limitations, sitting in a chair for your meditation is great. This is also good to remember for anyone who wants to meditate during their commute to work or at a park.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Laying Down&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;While not ideal, learning how to meditate while laying down can help many people overcome insomnia.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What should I do with my hands?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You may notice some interesting hand positions in meditation statues, often referred to as mudras.&lt;/p&gt;

&lt;p&gt;While they have pretty interesting interpretations, one of the easiest is to lay your hands comfortably in your lap. Really it's about making sure your shoulders are relaxed.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Practice
&lt;/h4&gt;

&lt;p&gt;While I'm going to focus on concentration practice, there are an endless number of meditation practices out there. My personal favorites tend to be noting practice and self-inquiry. I'll put a list of resources at the end of the post.&lt;/p&gt;

&lt;p&gt;But concentration is a great place to start. It has the most immediate "feeling better" results, especially if you take the time to really enjoy your time taking a break from the a noisy world.&lt;/p&gt;

&lt;p&gt;Again, and to repeat this over and over and over again, you &lt;em&gt;will not&lt;/em&gt; be able to quiet your thoughts. You &lt;em&gt;will&lt;/em&gt; get distracted by work dramas, or life issues, or anything else that pops up into your psyche.&lt;/p&gt;

&lt;p&gt;But stop seeing these as distractions. Rather, this is about the continual act of observing your thoughts and realizing that they're "over there" and you're "over here."&lt;/p&gt;

&lt;p&gt;To take it one step back for a second: A thing observed can never be its observer.&lt;/p&gt;

&lt;p&gt;If you are observing your thoughts, you are therefore not them. While meditating remember this dynamic when you get lost in thought, acknowledge your thoughts, and then gently guide yourself to your concentration. This is a great moment to practice patience and be understanding to yourself.&lt;/p&gt;

&lt;p&gt;Between that dance, which happens over and over again, set yourself a goal of focusing on the breath exiting your nose.&lt;/p&gt;

&lt;p&gt;Try to sense it flowing in and out of your nostrils. See if you can even concentrate strong enough to feel it flowing across your nose hairs.&lt;/p&gt;

&lt;p&gt;Next focus on the cyclical rhythm of your breath. Feel it flow out of your nose, then back in. See if you can concentrate on the exact moment when you shift from breathing out to breathing in.&lt;/p&gt;

&lt;p&gt;See if you can notice when your breath begins and ends. See if you can sense when it feels like it's "the middle" of your breath.&lt;/p&gt;

&lt;p&gt;You can even use a naming convention to it. Something like, "in" and "out" or "start", "middle", and "end".&lt;/p&gt;

&lt;p&gt;See if after awhile you can shift from speaking these things in your head, to wordlessly recognizing the same breathing cycle.&lt;/p&gt;

&lt;p&gt;If you feel like it's beginning to be hard to focus on your breath, you can try focusing on something else - like your hands resting, your chest breathing, your diaphragm rising and falling, etc.&lt;/p&gt;

&lt;p&gt;It's ok to not do this perfectly, and do it in your own way. The most important aspect is attempting to maintain focused on your object of focus, and eventually widening to what's around you.&lt;/p&gt;

&lt;p&gt;But first and foremost, just enjoy your sit. Allow thoughts to rise, allow yourself to try (and fail) to concentrate. Be patient with the process, and allow all the hidden benefits discover themselves.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;I would recommend Mastering The Core Teachings of The Buddha or The Mind Illuminated for anyone wanting to have an indepth explanation for &lt;strong&gt;how&lt;/strong&gt; to mediate.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://integrateddaniel.info/book" rel="noopener noreferrer"&gt;Mastering The Core Teachings of The Buddha by Daniel Ingram - http://integrateddaniel.info/book&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/Mind-Illuminated-Meditation-Integrating-Mindfulness/dp/1501156985" rel="noopener noreferrer"&gt;The Mind Illuminated by Culadasa (John Yates) - https://www.amazon.com/Mind-Illuminated-Meditation-Integrating-Mindfulness/dp/1501156985&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/Zen-Mind-Beginners-Informal-Meditation/dp/1590308492" rel="noopener noreferrer"&gt;Zen Mind, Beginner's Mind by Shunryu Suzuki - https://www.amazon.com/Zen-Mind-Beginners-Informal-Meditation/dp/1590308492&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.brightmind.com/" rel="noopener noreferrer"&gt;Brightmind - Shinzen Young meditation app - https://www.brightmind.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.buddhistgeeks.org/" rel="noopener noreferrer"&gt;Buddhist Geeks - https://www.buddhistgeeks.org/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://deconstructingyourself.com/" rel="noopener noreferrer"&gt;Deconstructing Yourself - https://deconstructingyourself.com/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>career</category>
      <category>selfcare</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A Visual Strategy To Handle On-Going Tasks</title>
      <dc:creator>Ricardo Delgado</dc:creator>
      <pubDate>Mon, 21 Oct 2019 11:43:38 +0000</pubDate>
      <link>https://dev.to/rdelga80/a-visual-strategy-to-handle-on-going-tasks-50d0</link>
      <guid>https://dev.to/rdelga80/a-visual-strategy-to-handle-on-going-tasks-50d0</guid>
      <description>&lt;p&gt;Is there anything harder than getting your workflow in order? Between bullet journals, Trello, Monday.com, Git, or whatever else it may take to get things in order, it's obvious that keeping things tidy is quite a challenge - I'm especially looking at you solo entrepreneurs and freelancers.&lt;/p&gt;

&lt;p&gt;While it feels like technology should be the best way to solve this problem, like with many things, it doesn't quite get the job done.&lt;/p&gt;

&lt;p&gt;How many tasks are left open because you didn't want to add that last note to close out a task? How many journals have the first few pages filled out, only to get frustrated with the monthly task of re-writing and re-organizing what you've accomplished (which seems like way too many)? Who hasn't gotten annoyed at the tedium of rewriting the same task every month?&lt;/p&gt;

&lt;p&gt;For something like this I like to go old school. And I thought I'd share an organizational strategy I find very helpful to get long-term tasks accomplished (or keep long on my radar).&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep It Visual
&lt;/h2&gt;

&lt;p&gt;Like holding a book, looking at a globe, or admiring the paint strokes on a Van Gogh painting - sometimes it's better to see something in front of you to really "feel" what's going on.&lt;/p&gt;

&lt;p&gt;For my Visual Organizer I use cut up index cards pinned into a corkboard. You could just as easily use Post-it Notes and tape, even though I prefer pins because they don't lose their stickiness.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YC-gYkKn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/btam03yqtwbwz2d0772x.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YC-gYkKn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/btam03yqtwbwz2d0772x.jpg" alt="Slips of paper cut to two different sizes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cut your paper into two different sizes. The larger papers are going to be for the day headings, and the smaller ones will be your tasks.&lt;/p&gt;

&lt;p&gt;The board is set up so there are series of multiple tasks on the left, while the days of a work week (for me it's Monday to Sunday) are set to the right.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8lnxJbYY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/hm6o2clfrj1fxkjywiex.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8lnxJbYY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/hm6o2clfrj1fxkjywiex.jpg" alt="Slips of paper on a corkboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While other organizers focus on accomplished tasks, I'm focusing on establishing a work schedule in which I can track the attention I give to a certain task.&lt;/p&gt;

&lt;p&gt;In my experience it's far too easy to get lost doing a specific job, while others fall to the side as I go down the proverbial "get it done" rabbit hole.&lt;/p&gt;

&lt;p&gt;Instead, I want to focus on carving out time in my schedule to work on specific tasks while visually seeing what else I have to do.&lt;/p&gt;

&lt;p&gt;The idea is to break down my task slips by the amount of days per week I'm willing to focus on a particular job.&lt;/p&gt;

&lt;p&gt;Big jobs may need attention for every day of the week, therefore requiring 7 slips. While smaller jobs may only need two or three days per week (2 or 3 slips).&lt;/p&gt;

&lt;p&gt;The amount of time you want to spend on each is entirely up to you, and determined by how many tasks you are trying to accomplish. A good possible strategy is writing a specific amount of time you're willing to give that task on each slip, and setting a timer as you work on it.&lt;/p&gt;

&lt;p&gt;The key is not focusing on completing a job, but rather, giving consistent attention to a multitude of tasks, inching each closer to the finish line without any stragglers.&lt;/p&gt;

&lt;p&gt;As each job is given attention for the day, then you move the task under the day in which you worked on the task.&lt;/p&gt;

&lt;p&gt;As you fill out your week, you can visually see what hasn't been given attention, and what is.&lt;/p&gt;

&lt;p&gt;Then, at the end of the week, you move your pins back to the beginning and start over again.&lt;/p&gt;

&lt;p&gt;A good example would be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;5 slips dedicated to a solo business project&lt;/li&gt;
&lt;li&gt;3 slips dedicated to a course you want to take online&lt;/li&gt;
&lt;li&gt;2 slips dedicated to learning a new language&lt;/li&gt;
&lt;li&gt;2 slips dedicated to a small portfolio project&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is a strategy to complete tasks that can last several days, weeks, or even years. This is about properly parsing your attention, so that nothing can fall through the cracks.&lt;/p&gt;

</description>
      <category>career</category>
      <category>productivity</category>
    </item>
    <item>
      <title>VueJS Testing: What Not How</title>
      <dc:creator>Ricardo Delgado</dc:creator>
      <pubDate>Mon, 14 Oct 2019 20:30:33 +0000</pubDate>
      <link>https://dev.to/rdelga80/vuejs-testing-what-not-how-hn4</link>
      <guid>https://dev.to/rdelga80/vuejs-testing-what-not-how-hn4</guid>
      <description>&lt;p&gt;I've been focused so much on testing within VueJS lately that I really wanted to get some thoughts about it down in a post.&lt;/p&gt;

&lt;p&gt;This especially occurred to me yesterday as I was writing a new component, and approached it purely from a Test Driven Design (TDD) direction.&lt;/p&gt;

&lt;p&gt;When I first heard of TDD it seemed totally unappealing. I couldn't mentally integrate writing tests before code.&lt;/p&gt;

&lt;p&gt;Before getting started, let me clarify that this is not a tutorial on tests or testing in VueJS. I'm assuming that you may have taken a stab at testing and became frustrated or didn't see the use in it (a position I was in for quite a long time myself).&lt;/p&gt;

&lt;p&gt;Even though this post isn't about how you go about writing tests, Vue has tremendous documentation on it.&lt;/p&gt;

&lt;p&gt;Here's my personal favorite resources on writing tests in VueJS:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://vue-test-utils.vuejs.org"&gt;Vue Test Utils&lt;/a&gt;&lt;br&gt;
&lt;a href="https://lmiller1990.github.io/vue-testing-handbook/"&gt;Vue Testing Handbook by lmiller1990&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.manning.com/books/testing-vue-js-applications"&gt;Edd Yerburgh's Testing Vue.JS Applications&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To start with, my non-test driven way of coding would usually entail writing lots of lines of code, and when I thought of another feautre I wanted then I'd write the appropriately needed functionality.&lt;/p&gt;

&lt;p&gt;For example, if I was writing a page for a calendar, I would start first with the main Vue file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then wholesale write some code to accomplish what I wanted:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;currentDate&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;dayOfWeek&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Test&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&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="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;The title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="na"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;currentDate&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="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nx"&gt;dayOfWeek&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getDay&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="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alright, great, a nice and easy to understand a Vue component file... but actually, I just realized I want this calendar to show multiple days of the week.&lt;/p&gt;

&lt;p&gt;And what about date formats?&lt;/p&gt;

&lt;p&gt;And what about in various languages?&lt;/p&gt;

&lt;p&gt;And...&lt;br&gt;
And...&lt;br&gt;
And...&lt;/p&gt;

&lt;p&gt;Anyone who's built an application should know this feeling. And while this example is very straight forward, what happens when it's not?&lt;/p&gt;

&lt;p&gt;Something that is incredibly appealing about Test Driven Design is that it slows down the process.&lt;/p&gt;

&lt;p&gt;Sitting down and slamming your keyboard over and over again, may get digital letters, numbers, and symbols to pop up on your monitor, but is it necessarily effective in the long run?&lt;/p&gt;

&lt;p&gt;Of course, if you have a pretty small, simple project, then by all means feel free to skip TDD, but keep in mind the point of TDD is to &lt;em&gt;break your code down into small manageable parts.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Which leads to the first major mental hurdle about testing I'd like to make:&lt;/p&gt;
&lt;h3&gt;
  
  
  Break Your Code Down Into Easy To Manage Pieces
&lt;/h3&gt;

&lt;p&gt;It's so hard not to indulge the awesomeness of programming and write super complex functions to handle whatever your component may need.&lt;/p&gt;

&lt;p&gt;Without a doubt coding is fun, interesting, and compelling all at the same time. Its power will course through electronic veins and arteries like lightning combusting a tree in the middle of a lonely forest.&lt;/p&gt;

&lt;p&gt;But it wasn't until I came across this slightly unrelated example in &lt;a href="https://vuejs.org/v2/style-guide/#Simple-computed-properties-strongly-recommended"&gt;VueJS's official style guide for simple computed properties&lt;/a&gt; that gave me a programmatic epiphany:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bad&lt;/strong&gt;&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="nx"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;basePrice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;manufactureCost&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="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;profitMargin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nx"&gt;basePrice&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;
      &lt;span class="nx"&gt;basePrice&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;discountPercent&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Good&lt;/strong&gt;&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="nx"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;basePrice&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;manufactureCost&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="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;profitMargin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="nx"&gt;discount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;basePrice&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;discountPercent&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="nx"&gt;finalPrice&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;basePrice&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;discount&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I've seen that bad example in my code a million times, and without getting too lost in the details, the point is to focus on the concept of breaking things down to make them easier to digest.&lt;/p&gt;

&lt;p&gt;While this is a good rule for almost every aspect of writing code, it also makes a lot of sense in testing, and I would argue is a good place to start to write "testable code."&lt;/p&gt;

&lt;p&gt;For example, imagine a method that you want to test that looks 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="nx"&gt;testCode&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&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;variable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;computedValue&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;   
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;transformValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&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;variable&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;

&lt;span class="p"&gt;...&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You get the point.&lt;/p&gt;

&lt;p&gt;I used to think that there was a flaw with testing while attempting to tackle a complex function that I'd written.&lt;/p&gt;

&lt;p&gt;As I attempted to write my way out of a maze of nested functions and asynchronous behaviors that functioned the way I wanted, I'd find that it wasn't easy to write tests at all for it.&lt;/p&gt;

&lt;p&gt;Looking at the above &lt;code&gt;testCode&lt;/code&gt; method, there's at least four different aspects that need to be mocked to get a single test to work.&lt;/p&gt;

&lt;p&gt;Unfortunately, you'll find yourself wondering why even write the test at all, since it &lt;em&gt;feels&lt;/em&gt; as if the entire function requires every aspect to be mocked anyway.&lt;/p&gt;

&lt;h3&gt;
  
  
  Writing Testable Code, A Subset of Test Driven Design
&lt;/h3&gt;

&lt;p&gt;The more that I work with tests the more I'm willing to believe that tests don't hold much value unless your code was written with Test Driven Design.&lt;/p&gt;

&lt;p&gt;On the one hand, it is entirely possible to revisit your code, and try to think your way through what tests need to be written by analyzing what's there.&lt;/p&gt;

&lt;p&gt;Take the following 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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;{ myClass: isTrue }&lt;/span&gt;&lt;span class="dl"&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="nx"&gt;companyName&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;{ hidden: showDiv }&lt;/span&gt;&lt;span class="dl"&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="nx"&gt;warning&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;click&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;isTrue = !isTrue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nx"&gt;Click&lt;/span&gt; &lt;span class="nx"&gt;me&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/template&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;companyName&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Test&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&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="na"&gt;isTrue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="na"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;showDiv&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isTrue&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nx"&gt;warning&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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;companyName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is a warning.`&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/style&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Coming upon a very short snippet of code like this definitely makes it easy to breakdown code to write tests.&lt;/p&gt;

&lt;p&gt;You may even just build your tests by analyzing the component from top to bottom.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When &lt;code&gt;isTrue&lt;/code&gt; is true does it render &lt;code&gt;myClass&lt;/code&gt; in the main &lt;code&gt;div&lt;/code&gt;'s classes.&lt;/li&gt;
&lt;li&gt;Does the &lt;code&gt;companyName&lt;/code&gt; prop render correctly?&lt;/li&gt;
&lt;li&gt;Does the rendered style show properly from the &lt;code&gt;showDiv&lt;/code&gt; computed property?&lt;/li&gt;
&lt;li&gt;Does the &lt;code&gt;warning&lt;/code&gt; computed property return the &lt;code&gt;companyName&lt;/code&gt; prop properly in the string that's defined?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Etc.&lt;/p&gt;

&lt;p&gt;The problem with building a component's tests after the code has been written is that it doesn't &lt;em&gt;tell the story of the component.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;While the tests above may address the technical specifications of the code, it doesn't address the intentions of the component.&lt;/p&gt;

&lt;p&gt;Instead, let's look at how Test Driven Design writes the component, and pay attention to how it helps drive the mental clarity of &lt;em&gt;what&lt;/em&gt; is being written, not just &lt;em&gt;how&lt;/em&gt; it's being written.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Make sure the component renders correctly, and this is known as a sanity test and should be the first test in every test file.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Test:&lt;/em&gt;&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;TestComponent&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;src/components/TestComponent.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wrapper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;shallowMount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;TestComponent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sanity test&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&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="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isVueInstance&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Corresponding code&lt;/em&gt;: Creating a file in the components folder named TestComponent.vue.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Insure you're receiving the correct props.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This gets tested before rendering because logically, you would need to receive the prop before it can be used (meaning you wouldn't be able to test anything dependent on it).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Test:&lt;/em&gt;&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="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;receives companyName prop&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&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="nx"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setProps&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;companyName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;test&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;companyName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;test&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Corresponding Code:&lt;/em&gt;&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/template&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;companyName&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Set proper checks for companyName prop, not allowing for non-alphanumeric characters to be used in name.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Test:&lt;/em&gt;&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="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;companyName prop checks for validity&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&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="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;vm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;companyName&lt;/span&gt;
  &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;required&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toBeTruthy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&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;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;validator&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;validator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;test name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toBeTruthy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;validator&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;validator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;test ^&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toBeFalsy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Corresponding Code:&lt;/em&gt;&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;validator&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[^&lt;/span&gt;&lt;span class="sr"&gt;a-zA-Z0-9 &lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;em&gt;Note:&lt;/em&gt;&lt;/em&gt; Notice how each test only creates the very smallest amount of code needed to satisfy it. While there may be a concern of tedium, the long term clarity of development will be evident.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. The companyName prop renders&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Test:&lt;/em&gt;&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="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;companyName prop renders validly&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&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="nx"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setProps&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;companyName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;test name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toContain&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;test name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Corresponding Code:&lt;/em&gt;&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;companyName&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/template&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;As you can see over just four tests, there's a much clearer direction to what is being built by starting with tests first.&lt;/p&gt;

&lt;p&gt;The next tests would progress in an order similar to this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;warning computed property is returning the correct string&lt;/li&gt;
&lt;li&gt;when clicking the button does it change the data value&lt;/li&gt;
&lt;li&gt;does the hidden class render when the button is clicked&lt;/li&gt;
&lt;li&gt;etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each test dictating what the following test would be, like a digital karmic flow.&lt;/p&gt;

&lt;p&gt;Building the component from bottom up allows for a much more succinct connection between all the aspects of the component. Your code will follow a logical progression of steps, rather than a "build as needed" style of development.&lt;/p&gt;

&lt;p&gt;The simplicity will allow for longer-term understanding of what's being built, plus all the positive benefits of having 100% coverage on your code (since each line only exists because there is a test for it).&lt;/p&gt;

</description>
      <category>vue</category>
      <category>testing</category>
      <category>programming</category>
    </item>
    <item>
      <title>What I Learned My First Week at My First Dev Job</title>
      <dc:creator>Ricardo Delgado</dc:creator>
      <pubDate>Mon, 07 Oct 2019 10:22:05 +0000</pubDate>
      <link>https://dev.to/rdelga80/what-i-learned-my-first-week-at-my-first-dev-job-3on5</link>
      <guid>https://dev.to/rdelga80/what-i-learned-my-first-week-at-my-first-dev-job-3on5</guid>
      <description>&lt;p&gt;One day I'm filling out job applications, doing Leetcode until my head is doing somersaults, and then the next day I'm in.&lt;/p&gt;

&lt;p&gt;To think that just about a year ago I wrote about &lt;a href="https://dev.to/rdelga80/the-fear-and-the-trial-590k"&gt;my fears of even attempting to look for a developer job&lt;/a&gt;, and now I'm looking back at my first week as a professional software engineer.&lt;/p&gt;

&lt;p&gt;It's still hard to believe, even though the reality of my day-to-day is so familiar and tangible.&lt;/p&gt;

&lt;p&gt;This post is for anyone still on the outside looking in. I'm one of the most guilty of imposter syndrome, and worry everyday if I'm capable of doing this job.&lt;/p&gt;

&lt;p&gt;Thankfully, my first week flew by and a lot of my initial concerns are dissipating. Most surprising was what actually seemed to be important to the position - which had much less to do about code than I previously thought.&lt;/p&gt;

&lt;p&gt;Even though I only have one week under my belt, here's some things that I'm wishing I'd spent more time focusing on in preparation for the position.&lt;/p&gt;

&lt;h2&gt;
  
  
  Communication is Key
&lt;/h2&gt;

&lt;p&gt;I'd seen terms like "Agile" or "Scrum" thrown around Twitter or Reddit programming circles, but I never quite paid attention because I didn't make the connection on their importance to a person's ability to code in a team.&lt;/p&gt;

&lt;p&gt;Without a doubt, Scrum has been the biggest focus of my first week.&lt;/p&gt;

&lt;p&gt;And if you really think about it, it makes so much sense and flies in the face of the independent and isolated nature of the process of learning how to code.&lt;/p&gt;

&lt;p&gt;From &lt;a href="https://en.wikipedia.org/wiki/Scrum_(software_development)"&gt;Wikipedia entry on Scrum (software development)&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Scrum is an agile process framework for managing complex knowledge work, with an initial emphasis on software development, although it has been used in other fields and is slowly starting to be explored for other complex work, research and advanced technologies. It is designed for teams of ten or fewer members, who break their work into goals that can be completed within timeboxed iterations, called sprints, no longer than one month and most commonly two weeks, then track progress and re-plan in 15-minute time-boxed stand-up meetings, called daily scrums."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To properly think of Scrum, I put it in terms of a modern military.&lt;/p&gt;

&lt;p&gt;In the past, an Army would be made up of large battalions of specific units - infantry are foot solders, cavalry are mounted units, etc.&lt;/p&gt;

&lt;p&gt;But the modern military has gotten more complex and sophisticated, relying more on speed and agility rather than blunt force and numbers.&lt;/p&gt;

&lt;p&gt;Instead of large battalions of specifically skilled units, there's been a movement towards "commando groups." These groups are a mix of all different skilled units - it may include a few small infantry Platoons, supported by a couple of mounted units, a few air support units, etc.&lt;/p&gt;

&lt;p&gt;By, taking a giant army, and parsing it down to smaller versions of itself, it creates a powerful unit that can more rapidly deal with issues in the field.&lt;/p&gt;

&lt;p&gt;Scrum uses a similar mentality for software development. Instead of front-end engineers working independently from  back-end engineer, Scrum Teams are a mix of five or so people with complimentary skills trying to solve specific tasks in two to four week cycles called Sprints.&lt;/p&gt;

&lt;p&gt;It's like parsing down a large corporation into a bunch of startups.&lt;/p&gt;

&lt;p&gt;There's a lot of structure in the system, which includes daily meetings, meetings every other week or a month, one-on-one meetings, etc, and a focus on good documentation of work done and work to be done.&lt;/p&gt;

&lt;p&gt;Basically, my biggest misunderstanding of the job was just how much I'd be working with other programmers, business people, an administrators who don't necessarily know what I'm doing.&lt;/p&gt;

&lt;p&gt;It became clear right away that the fundamental aspect to my job is knowing how to collaborate, not just write good code.&lt;/p&gt;

&lt;p&gt;I realized that I'd made a mistake of not taking opportunities to do Hackathons, and instead focused on the specifics of the language I would be working with.&lt;/p&gt;

&lt;p&gt;In hindsight I see that going to meetups could've prepared me better for the position.&lt;/p&gt;

&lt;h2&gt;
  
  
  Github, Jira, and Coding Standards
&lt;/h2&gt;

&lt;p&gt;These could also fall under the umbrella of collaboration, but I set it off to its own space because this is more about collaborating via your code, rather than the management of collaboration.&lt;/p&gt;

&lt;p&gt;I am truly intimidated by Github. While Github Desktop has made it much simpler to manage local and remote repositories, it's still not the easiest thing to wrap my head around.&lt;/p&gt;

&lt;p&gt;This will definitely come as things go, but in the meantime here's an awesome site to help you learn about Git Branching, and other features of Git: &lt;a href="https://learngitbranching.js.org/"&gt;https://learngitbranching.js.org/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Jira is a service that keeps track of tasks that are determined in Scrum meetings. Truthfully I haven't had to work with it yet, but knowing that it will be vital I wish I would've invested more energy into learning it ahead of time.&lt;/p&gt;

&lt;p&gt;Think Trello, but that can easily be tied into code.&lt;/p&gt;

&lt;p&gt;And with there being such an obvious emphasize on readability, knowing how to maintain documentation and adhere to coding standards is vital.&lt;/p&gt;

&lt;p&gt;Here's a few resources that I've been using daily - I work in VueJS so these are mostly specific to that framework, but there should be equivalent ones for whatever framework or language you work with:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://a11yproject.com/checklist/"&gt;The A11Y Project Checklist (Accessibility)&lt;/a&gt;&lt;br&gt;
&lt;a href="https://vuejs.org/v2/style-guide/"&gt;VueJS Style Guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, in my project we're using Storybooks, which is a tool for developing UI components in isolation. I had never worked with it before the project, but I could see it being a great item to add to your resume:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://storybook.js.org/"&gt;StorybookJS&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing and Thoughtful Development
&lt;/h2&gt;

&lt;p&gt;The days of my independent Mad Max-like programming is over.&lt;/p&gt;

&lt;p&gt;Another perk of being isolated is the ability to write whatever you want, however you want.&lt;/p&gt;

&lt;p&gt;Being part of a team changes all of that, and one of the many decisions you'll have to keep in mind with your code is if it'll be digestible by other people.&lt;/p&gt;

&lt;p&gt;As I start diving into the codebase it dawns on me more and more that there is going to be a lot of eyes looking at what I've written. And whatever that is it needs to be understood easily and quickly.&lt;/p&gt;

&lt;p&gt;While everyone agrees testing is important, and especially vital in Scrum development, it's such an easy thing to toss aside because it can become a perceived sticky spot.&lt;/p&gt;

&lt;p&gt;While I'm okay with testing, it's an area that I wish I had spent even more time focused on. Being &lt;em&gt;expertly&lt;/em&gt; fluent in writing tests will make writing code an absolute breeze. Plus it will make it much easier for others to work with what you've done.&lt;/p&gt;

&lt;p&gt;Not to dive too deeply into it, but from what I've seen, when Test Driven Design is coupled with Component Driven Design, it makes writing tests a whole lot easier.&lt;/p&gt;

&lt;p&gt;Some VueJS testing resources:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://vue-test-utils.vuejs.org/"&gt;Vue Test Utils Documentation&lt;/a&gt;&lt;br&gt;
&lt;a href="https://lmiller1990.github.io/vue-testing-handbook/"&gt;VueJS Testing Handbook&lt;/a&gt;&lt;br&gt;
&lt;a href="https://jestjs.io/docs/en/getting-started"&gt;Jest Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also check out my previous post about an awesome book on testing by VueJS Core team member and author of Vue Test Utils Edd Yerburgh: &lt;a href="https://dev.to/rdelga80/treasure-map-to-vue-js-testing-gold-1nle"&gt;Treasure Map to Vue Testing Gold&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Can't wait to see what week 2 brings!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>career</category>
      <category>agile</category>
    </item>
    <item>
      <title>Treasure Map to Vue.js Testing Gold</title>
      <dc:creator>Ricardo Delgado</dc:creator>
      <pubDate>Fri, 04 Oct 2019 09:58:47 +0000</pubDate>
      <link>https://dev.to/rdelga80/treasure-map-to-vue-js-testing-gold-1nle</link>
      <guid>https://dev.to/rdelga80/treasure-map-to-vue-js-testing-gold-1nle</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WM9oz6nB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/k2na2zwvpuld7g5890v3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WM9oz6nB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/k2na2zwvpuld7g5890v3.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The idea of testing is so fulfilling. Planning your way through your code, creating reliable trail markers that will keep your code bug free, it's every compulsively organized coder's dream.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;BUT&lt;/strong&gt; in reality, testing can be closer to wandering around the woods, hoping to stumble into a solution that makes sense to creating better and hopefully faster code.&lt;/p&gt;

&lt;p&gt;Personally, I struggle with testing. I'm a natural planner and organizer, and I can see that testing should be such an effective way to get ahead of my future self and let him know that hour twelve of a programming day may not be the most effective time to be pushing out lines of code.&lt;/p&gt;

&lt;p&gt;As a Vue developer there has been times where I'm left confounded by testing within the intricacies of Vue's framework. While Vue is notoriously well known for it's well written documentation, I was often left scratching my head and moved on from writing tests out of frustration.&lt;/p&gt;

&lt;p&gt;When it was announced last year by &lt;a href="https://www.manning.com/books/testing-vue-js-applications"&gt;Manning Publications&lt;/a&gt; that they were publishing a book on Vue testing by Edd Yerburgh, core Vue team member and the author of Vue Test Utils, I immediately purchased the "Manning Early Release Program" (MEAP) version.&lt;/p&gt;

&lt;p&gt;Being able to get the perspective of a core Vue member on their product is really helpful, and I'd recommend seeking out the opinions of an original author as one of the best ways to learn about a topic.&lt;/p&gt;

&lt;p&gt;While some people may be able to learn strictly through documentation, I feel I may reflect a potential case for some incoming issues in the developer community.&lt;/p&gt;

&lt;p&gt;Being a person who has a non-technical background but self-taught my way into being a professional developer, I usually can't wrap my head around technical documentation that easily.&lt;/p&gt;

&lt;p&gt;Usually, along with whatever technical documentation I may be going over, I'll have a few tutorials open alongside, flipping back and forth trying to decode the words that at times feel like they were written in Ancient Sumerian.&lt;/p&gt;

&lt;p&gt;To me this is the biggest strength of Yerburgh's book. It is extremely well written, and very easy to read and understand.&lt;/p&gt;

&lt;p&gt;It's so simple, in fact, that even though it's recommended to code along with the book's examples, I nonetheless find myself reading the book and absorbing the information without necessarily needing to sit in front of a computer at the same time.&lt;/p&gt;

&lt;p&gt;The book catches most of the important topics, such as Vuex, Server Side Rendering (SSR), child and parent components, unit tests, end to end tests, etc.&lt;/p&gt;

&lt;p&gt;Of course, like with all guides of a particular tool, you'll still find all sorts of things to drive you crazy during implementation, but a quick flip back into Yerbugh's book, or &lt;a href="https://vue-test-utils.vuejs.org/"&gt;Vue Test Util's documentation&lt;/a&gt; usually provides a good roadmap out of whatever issue you may find yourself in.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.manning.com/books/testing-vue-js-applications"&gt;Purchase Testing Vue.js Applications from Manning Publications&lt;/a&gt;&lt;br&gt;
&lt;a href="https://vue-test-utils.vuejs.org"&gt;VueJS Testing Documentation&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/eddyerburgh"&gt;Edd Yerburgh's Github&lt;/a&gt;&lt;br&gt;
&lt;a href="https://twitter.com/eddyerburgh"&gt;Edd Yerburgh's Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>testing</category>
      <category>resources</category>
      <category>learning</category>
    </item>
    <item>
      <title>All The Ways That I Failed At "Sum 3"</title>
      <dc:creator>Ricardo Delgado</dc:creator>
      <pubDate>Sat, 07 Sep 2019 19:00:47 +0000</pubDate>
      <link>https://dev.to/rdelga80/all-the-ways-that-i-failed-at-sum-3-3a3c</link>
      <guid>https://dev.to/rdelga80/all-the-ways-that-i-failed-at-sum-3-3a3c</guid>
      <description>&lt;p&gt;I have a problem in my life and it's name is Leetcode.&lt;/p&gt;

&lt;p&gt;While trying to think of topics to write about on DEV, I kept reading all these posts from talented developers who write so authoritatively about coding and I couldn't help be think, "I definitely cannot do that."&lt;/p&gt;

&lt;p&gt;It seems like most coders' solutions and strategies to coding problems come so clearly. In the meantime, I approach solving problems like a monkey slapping at buttons until a banana pops up in my console so I can scream in delight.&lt;/p&gt;

&lt;p&gt;But most importantly is to just enjoy the process. Coding is so much fun, so I thought I'd share my coding failures (and sometimes successes).&lt;/p&gt;

&lt;h2&gt;
  
  
  Sum 3
&lt;/h2&gt;

&lt;p&gt;Sum 3 is a mean-spirited twist on another Leetcode problem called Sum 2. Where in Sum 2 you loop through an array adding two elements until they equal to a target number, Sum 3 uses three.&lt;/p&gt;

&lt;p&gt;Oh, and with the caveat that of only using each element once per 3 array pairing.&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;var&lt;/span&gt; &lt;span class="nx"&gt;sum3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&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;target&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="c1"&gt;// magic&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&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;0&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="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nx"&gt;sum3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&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;// [ [-1, 0, 1], [-1, -1, 2] ]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Attempt 1: Hitting It With A Hammer
&lt;/h3&gt;

&lt;p&gt;My first, and totally useless attempt at a problem like this, is to shove it into a meat grinder, turn the crank, and hope sausage comes out at the end.&lt;/p&gt;

&lt;p&gt;In this case, its about running as many for loops as humanly possible praying that there's some kind of solution in it, and then maniacally laughing as my browser catches fire and melts my hard drive into a puddle of plasticy goo.&lt;/p&gt;

&lt;p&gt;Attempt 1:&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;var&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&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;0&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="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&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;var&lt;/span&gt; &lt;span class="nx"&gt;threeSum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&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;var&lt;/span&gt; &lt;span class="nx"&gt;solution&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="kd"&gt;let&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;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;c&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;sum&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;solution&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;c&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="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;solution&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alright, straight to the point. No muss. No fuss.&lt;/p&gt;

&lt;p&gt;Let's check the output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
  [-1,-1,2],[-1,0,1],[-1,1,0],[-1,2,-1],[-1,2,-1],
  [-1,-1,2],[0,-1,1],[0,0,0],[0,1,-1],[0,1,-1],
  [0,-1,1],[1,-1,0],[1,0,-1],[1,0,-1],[1,-1,0],
  [2,-1,-1],[2,-1,-1],[2,2,-4],[2,-1,-1],[2,-1,-1],
  [2,-4,2],[-1,-1,2],[-1,0,1],[-1,1,0],[-1,2,-1],
  [-1,2,-1],[-1,-1,2],[-4,2,2]
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Oh boy. Yeah, this isn't good.&lt;/p&gt;

&lt;p&gt;What went wrong? Right off the back, I can see two major problems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We use the same element in the array over and over again.&lt;/li&gt;
&lt;li&gt;There's duplicates all over the place.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Alright, we're going to implement something like this to address issue 1:&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&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;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;c&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;sum&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;solution&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]])&lt;/span&gt;   
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'm going to wrap the core of the algorithm in a conditional where if any of the variables are in the same position in the array, then the sum array won't push into the solution array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
  [-1,0,1],[-1,1,0],[-1,2,-1],[-1,-1,2],[0,-1,1],
  [0,1,-1],[0,1,-1],[0,-1,1],[1,-1,0],[1,0,-1],
  [1,0,-1],[1,-1,0],[2,-1,-1],[2,-1,-1],[-1,-1,2],
  [-1,0,1],[-1,1,0],[-1,2,-1]
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The duplication issue is a bit trickier.&lt;/p&gt;

&lt;p&gt;To stick with the theme of this attempt, let's lob a grenade and see how the pieces fall in the exact right place we need them to.&lt;/p&gt;

&lt;p&gt;First, let's sort the sum array, so that we can make sure it's in the same order no matter where it's found in the the nums array.&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&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;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sumArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]].&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&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;sum&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;solution&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sumArray&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok great. And what does that give us?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
  [-1,0,1],[-1,0,1],[-1,-1,2],[-1,-1,2],[-1,0,1],
  [-1,0,1],[-1,0,1],[-1,0,1],[-1,0,1],[-1,0,1],
  [-1,0,1],[-1,0,1],[-1,-1,2],[-1,-1,2],[-1,-1,2],
  [-1,0,1],[-1,0,1],[-1,-1,2]
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unfortunately JavaScript doesn't allow arrays to be directly compared, so something like this &lt;code&gt;[] === []&lt;/code&gt; won't work.&lt;/p&gt;

&lt;p&gt;That means writing a helper function to check if the new array is in the solution array.&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;var&lt;/span&gt; &lt;span class="nx"&gt;isInSolution&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newArray&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;solutionArray&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;let&lt;/span&gt; &lt;span class="nx"&gt;dup&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newArray&lt;/span&gt;

    &lt;span class="nx"&gt;solutionArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&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;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;array&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;a&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;dup&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&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;dup&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then we have to adjust the core to 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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&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;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sumArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]].&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&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;sum&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isInSolution&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sumArray&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;solution&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="nx"&gt;solution&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sumArray&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's fired up this bad boy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
  [-1,0,1],[-1,-1,2]
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Boom! Now that's how you get some Leetcoding done.&lt;/p&gt;

&lt;p&gt;Here's the complete code for Attempt 1:&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;var&lt;/span&gt; &lt;span class="nx"&gt;threeSum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&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;var&lt;/span&gt; &lt;span class="nx"&gt;solution&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&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;a&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="kd"&gt;let&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;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sumArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]].&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&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;sum&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isInSolution&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sumArray&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;solution&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
                        &lt;span class="nx"&gt;solution&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sumArray&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="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;solution&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;isInSolution&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newArray&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;solutionArray&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;let&lt;/span&gt; &lt;span class="nx"&gt;dup&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newArray&lt;/span&gt;

    &lt;span class="nx"&gt;solutionArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&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;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;array&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;a&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;dup&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&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;dup&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look at all that beautiful code. There's functions calling functions, there's a couple of instances of one liner sort functions, arrow functions, logic tests... now that's some verbose coding there!&lt;/p&gt;

&lt;p&gt;It's the equivalent of driving a Ford F-150 with mudding tires, chrome rims, flames painted across the sides, a big American flag, and Garth Brooks blasting on the radio just to go pick up a half gallon of milk from the Seven Eleven around the corner.&lt;/p&gt;

&lt;p&gt;This is gonna be amazing.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TIME LIMIT EXCEEDED&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well... I guess throwing three loops together isn't going to efficiently get the job done.&lt;/p&gt;

&lt;h3&gt;
  
  
  Attempt 2: If I Only Had A Brain
&lt;/h3&gt;

&lt;p&gt;Since hammers won't work, it's time to use a little finesse and actually think about what this problem is asking.&lt;/p&gt;

&lt;p&gt;The core question boils down to this: &lt;em&gt;a + b + c = 0&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;And if you really think about it, we only need to know two of the numbers, and make sure the third one exists.&lt;/p&gt;

&lt;p&gt;Let's try this whole thing from a different angle:&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;var&lt;/span&gt; &lt;span class="nx"&gt;threeSum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&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;var&lt;/span&gt; &lt;span class="nx"&gt;solution&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;newArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;firstNum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&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;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;newArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;secondNum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;diff&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstNum&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;secondNum&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&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;newArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;newArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="nx"&gt;solution&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;firstNum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;secondNum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;diff&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;solution&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The most biggest difference in this attempt is this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let diff = (firstNum + secondNum) * -1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should speed things up by letting us cut out one of the for loops in the previous attempt (&lt;em&gt;spoiler alert: it doesn't&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;When we run our first test run, we get this result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
  [-1,0,1],[-1,1,0],[-1,2,-1],[-1,-1,2],[0,-1,1],
  [0,1,-1],[0,-1,1],[1,-1,0],[1,0,-1],[1,-1,0],
  [2,-1,-1],[-1,-1,2],[-1,0,1],[-1,1,0],[-1,2,-1]
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is all starting to look a bit too familiar.&lt;/p&gt;

&lt;p&gt;So we go through the same steps as before, checking for duplication, yadda yadda yadda.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TIME LIMIT EXCEEDED&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well, if there's anything I've learned so far, if you need a very slow algorithm written, then I am your man (DM if interested).&lt;/p&gt;

&lt;h3&gt;
  
  
  Attempt 3: Being Clever
&lt;/h3&gt;

&lt;p&gt;I can't decide if these questions are specifically made so that you have to think your way out of a proverbial Labyrinth of excessive thinking, or if I loved knocking over my Lego towers with my He-Man action figures too much as a kid.&lt;/p&gt;

&lt;p&gt;There was definitely something to the &lt;em&gt;a + b + c = 0&lt;/em&gt; way of thinking. There's also something to the idea of avoiding walking through loops too much.&lt;/p&gt;

&lt;p&gt;While thinking things over, something popped into my head; the old tried and true &lt;strong&gt;merge sort&lt;/strong&gt; algorithm. The key to merge sort is to keep cutting the data down into more and more manageable pieces, until it's as easy as comparing two values.&lt;/p&gt;

&lt;p&gt;So let's try this...&lt;/p&gt;

&lt;p&gt;Like the line of thinking to add &lt;em&gt;a + b + c = 0&lt;/em&gt;, if an array is ordered, then the two extremes should be able to set the parameters of what could possibly equal to 0.&lt;/p&gt;

&lt;p&gt;Take our sample array: &lt;code&gt;[-1, 0, 1, 2, -1, -4]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When organized it becomes: &lt;code&gt;[2, 1, 0, -1, -1, -4]&lt;/code&gt; which means that the sum of the two most extreme numbers are: &lt;code&gt;2 + (-4) = -2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Walking closer to the center will bring the number closer to zero.&lt;/p&gt;

&lt;p&gt;Since the extremes currently add to &lt;code&gt;-2&lt;/code&gt; then moving the last element closer to the center will increase the total, and vice-versa if the sum is positive.&lt;/p&gt;

&lt;p&gt;The biggest benefit of this is that we've cut two loops in half.&lt;/p&gt;

&lt;p&gt;So let's get started.&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;var&lt;/span&gt; &lt;span class="nx"&gt;threeSum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&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="nx"&gt;solutionArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

    &lt;span class="nx"&gt;nums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First things first, we're going to sort the nums array in a descending order (highest to lowest).&lt;/p&gt;

&lt;p&gt;Next, we're going to add a couple of fail safes - you know, just in case Leetcode tries and trick us like the sneaky jerks they can be.&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;var&lt;/span&gt; &lt;span class="nx"&gt;threeSum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&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="nx"&gt;solutionArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

    &lt;span class="nx"&gt;nums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;a&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;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;solutionArray&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;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&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;nums&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="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&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="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&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="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we get to the meat of the algorithm.&lt;/p&gt;

&lt;p&gt;First we want to iterate through the array.&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="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&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;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;k&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The magic here is in the two variables we assign:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;j, which will be the beginning of our first half-loop&lt;/li&gt;
&lt;li&gt;k, which is the end of our second half-loops&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;"J" is the &lt;em&gt;next&lt;/em&gt; element in the array after the the current forEach element, and that "k" is the last element in the array.&lt;/p&gt;

&lt;p&gt;We're going to be walking the two ends of our array together, and seeing how many add to our target number of 0, until j and k meet (aka &lt;code&gt;j &amp;lt; k&lt;/code&gt;).&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="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&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;num&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;k&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;sum&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;solutionArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;k&lt;/span&gt;&lt;span class="p"&gt;]].&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;k&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As i iterates through, then the amount of elements j and k have to travel gets shorter on each iteration.&lt;/p&gt;

&lt;p&gt;It's simplicity is annoying. And certainly nothing that I would've ever realized on first seeing the problem.&lt;/p&gt;

&lt;p&gt;This is the complete code, including a few more adjustments to cover a few other special cases:&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;var&lt;/span&gt; &lt;span class="nx"&gt;threeSum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&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="nx"&gt;solutionArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

    &lt;span class="nx"&gt;nums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;a&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;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;solutionArray&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;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&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;nums&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="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&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="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&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="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&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;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;k&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&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;i&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="kd"&gt;let&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;num&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;k&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;sum&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nx"&gt;solutionArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;k&lt;/span&gt;&lt;span class="p"&gt;]].&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
                    &lt;span class="c1"&gt;// this step is to skip duplicate numbers in the array&lt;/span&gt;
                    &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
                    &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;k&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;k&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="nx"&gt;k&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;

                &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;k&lt;/span&gt;&lt;span class="o"&gt;--&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;solutionArray&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Click submit and &lt;strong&gt;SUCCESS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is definitely not something that I would have just been able to figure out. But probing the problem from different directions led to certain insights that gave way to a solution.&lt;/p&gt;

&lt;p&gt;And if anything, that's what I'd like to get across. I don't know how other programmers do it, but I'm certain wrong &lt;strong&gt;&lt;em&gt;way&lt;/em&gt;&lt;/strong&gt; more than I am right.&lt;/p&gt;

&lt;p&gt;But it's perfectly ok, because there is always insight from each failure, and you never know what'll lead to a break through to solve the problem.&lt;/p&gt;

&lt;p&gt;Onto the next challenge, and onto the next failure!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>code</category>
      <category>dev</category>
      <category>leetcode</category>
    </item>
  </channel>
</rss>
