<?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: Rembrandt Reyes (He/Him)</title>
    <description>The latest articles on DEV Community by Rembrandt Reyes (He/Him) (@rembrandtreyes).</description>
    <link>https://dev.to/rembrandtreyes</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%2F420058%2Fe5afd609-1702-44f4-8309-b1a3a059f706.png</url>
      <title>DEV Community: Rembrandt Reyes (He/Him)</title>
      <link>https://dev.to/rembrandtreyes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rembrandtreyes"/>
    <language>en</language>
    <item>
      <title>Ahhhh CVEs!</title>
      <dc:creator>Rembrandt Reyes (He/Him)</dc:creator>
      <pubDate>Wed, 02 Nov 2022 03:44:18 +0000</pubDate>
      <link>https://dev.to/rembrandtreyes/ahhhh-cves-266e</link>
      <guid>https://dev.to/rembrandtreyes/ahhhh-cves-266e</guid>
      <description>&lt;p&gt;Let me start by apologizing. I haven't been keeping up to date on my blog and I am ashamed of it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cCnPjAsz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r3buf776kqm3gazebjmf.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cCnPjAsz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r3buf776kqm3gazebjmf.gif" alt="Shame! Shame! Shame!" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I also almost forgot how to upload GIFs it's been that long!&lt;/p&gt;

&lt;h2&gt;
  
  
  Back to the topic
&lt;/h2&gt;

&lt;p&gt;So recently in my career, we have been heavily focused on addressing CVEs in our code. If you don't know what CVE stands for it is &lt;a href="https://en.wikipedia.org/wiki/Common_Vulnerabilities_and_Exposures"&gt;Common Vulnerabilities and Exposures&lt;/a&gt; (read more about it in the link). I am not going into too much detail about their history and whatnot. I want to focus on why we have been addressing them. So I assume you already know what CVEs are.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who cares about this stuff?
&lt;/h2&gt;

&lt;p&gt;It's all about your situation, are you delivering a product that needs ironclad security? Do you have customers that are knocking on your door to address these CVEs? Are you developing a project for yourself e.g. side-project? For me, we have customers that are scanning the bundle of code that we deliver to them and they report back if it passes their security inspection. For my projects, I have some repos that tell me I have double-digit security issues and I don't plan on addressing them 😂.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AZB0CEJP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2srh4hn62njbv23gi0vx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AZB0CEJP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2srh4hn62njbv23gi0vx.png" alt="Github security tab" width="312" height="116"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Are all CVEs the same?
&lt;/h2&gt;

&lt;p&gt;Again, that depends. There is a scale called &lt;strong&gt;Common Vulnerability Scoring System&lt;/strong&gt; (CVSS) to determine its severity NOT risk. Meaning these scores are meant to inform you of which vulnerabilities you should be prioritizing which could translate to risk, but I digress.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CVSS 3.x&lt;/strong&gt;&lt;br&gt;
Low - 0.1 - 3.9&lt;br&gt;
Medium - 4.0 - 6.9&lt;br&gt;
High - 7.0 - 8.9&lt;br&gt;
Critical - 9.0 - 10.0&lt;/p&gt;

&lt;h2&gt;
  
  
  Should they all be fixed?
&lt;/h2&gt;

&lt;p&gt;Short answer: Yes. Long answer: Yes, eventually. This is a huge oversimplification of the CVE world. So we'll dive into it a bit more. I primarily deal with front-end code and if you are a "smart" developer you'll be utilizing open-source packages to build your web app. And as gracious as I am to all the developers pushing packages to NPM I also get annoyed (for a few seconds) with them when the package they've created is no longer supported or has a very slow upgrade cycle. More about this below. I am not trying to start a witch hunt 😅.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's get to fixing
&lt;/h3&gt;

&lt;p&gt;So you finally get around to addressing those &lt;code&gt;Critical&lt;/code&gt; CVEs and you start to look through your lock file to find the culprit. Let's say in this instance you are trying to resolve issues with &lt;a href="https://nvd.nist.gov/vuln/detail/CVE-2021-44906"&gt;minimist &amp;lt;= 1.2.5&lt;/a&gt;. You are looking for all the packages that list minimist as a dependency and start upgrading them one by one. You almost have all packages upgraded, nearing the finish line and you get to &lt;code&gt;eslint-plugin-import&lt;/code&gt; a pretty popular plugin. &lt;code&gt;eslint-plugin-import&lt;/code&gt; has a dependency on &lt;code&gt;tsconfigs-path&lt;/code&gt; which has a dependency on &lt;code&gt;json5&lt;/code&gt; which has a dependency on &lt;code&gt;minimist&lt;/code&gt; with a version, you guessed it, &amp;lt;= 1.2.5. You fire off &lt;code&gt;yarn add -D eslint-plugin-import&lt;/code&gt; because YOLO and no upgrades were found. You check their GitHub to see if they have any updates to the package and you see this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XBZazQwM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m6uo78568ewiobgqflmc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XBZazQwM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m6uo78568ewiobgqflmc.png" alt="latest release" width="290" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The same package I have and it's been over a year since its last release. Jeez. Ok, let me take a look at PRs and see if they have something cooking. I find a draft PR &lt;a href="https://github.com/import-js/eslint-plugin-import/pull/2447"&gt;https://github.com/import-js/eslint-plugin-import/pull/2447&lt;/a&gt; and in that PR there is a long thread of people going back and forth about this upgrade. With some comments from people, you may know 👀&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hSCTBS6R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p2tw03q1z13eznfotmwe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hSCTBS6R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p2tw03q1z13eznfotmwe.png" alt="Kent C. Dodds" width="880" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;TL;DR the CVE isn't an issue for their package and they will not upgrade &lt;code&gt;tsconfig-paths&lt;/code&gt; to fix it. Great, this doesn't help me, because this is not an acceptable answer for our customers.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are my options?
&lt;/h3&gt;

&lt;p&gt;At this point, you have to make a decision.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A: Don't upgrade (big negative).&lt;/li&gt;
&lt;li&gt;B: Use the package that &lt;a href="https://github.com/JounQin"&gt;JounQin&lt;/a&gt; forked called &lt;a href="https://github.com/un-es/eslint-plugin-i#eslint-plugin-i"&gt;eslint-plugin-i&lt;/a&gt; which removes &lt;code&gt;tsconfig-paths&lt;/code&gt; and addresses the CVE (No, because I don't know JounQin's track record).&lt;/li&gt;
&lt;li&gt;C: Remove the plugin from your project (I was very tempted).&lt;/li&gt;
&lt;li&gt;D: Use resolutions in your &lt;code&gt;package.json&lt;/code&gt; (this).
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"resolutions": {
  "minimist": "1.2.6"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run &lt;code&gt;yarn install&lt;/code&gt; or &lt;code&gt;npm install&lt;/code&gt; and notice your lock file has "forced" an upgrade to the package version you specified. &lt;/p&gt;

&lt;p&gt;Resolutions are a great way to have your lock file to use a specified version. BUT be careful with the versions you are upgrading from -&amp;gt; to. You are mostly safe with minor and patch versions, but when breaking changes are introduced in major versions that can cause you a lot of headaches for your builds. For my use case, I went with option D, we want to address the CVEs and rarely want to use an exception if a resolution to the vulnerable package works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Change of pace
&lt;/h2&gt;

&lt;p&gt;There are a few benefits to fixing CVEs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I am getting very intimate with the projects I work on.&lt;/li&gt;
&lt;li&gt;When investigating a CVE in a package I use as a dependency I search through the code to see where these vulnerabilities live and get a better understanding of how the code works.&lt;/li&gt;
&lt;li&gt;It's nice to get away from coding, investigation work is always a nice little bonus and I believe it helps me build better maintainable code.&lt;/li&gt;
&lt;li&gt;Gives you a chance to interact with the OSS community. Raising issues or creating PRs to get some fixes in is great! And it shows you are trying to build a safer experience for your users and theirs.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>security</category>
      <category>react</category>
      <category>node</category>
    </item>
    <item>
      <title>Wait... how does React.useState work?</title>
      <dc:creator>Rembrandt Reyes (He/Him)</dc:creator>
      <pubDate>Thu, 20 Aug 2020 00:54:55 +0000</pubDate>
      <link>https://dev.to/rembrandtreyes/wait-how-does-react-usestate-work-44np</link>
      <guid>https://dev.to/rembrandtreyes/wait-how-does-react-usestate-work-44np</guid>
      <description>&lt;p&gt;So React hooks have been released for a while now and they are great! I have used them in production code and it makes everything look nicer. As I continued to use hooks, I started to wonder how all this magic works.&lt;/p&gt;

&lt;p&gt;Apparently I was not the only one because there was a Boston React meetup on this topic. Big Thank you to Ryan Florence and Michael Jackson (Not the Moonwalking legend) for giving such a great talk around the subject. Continue watching and you will learn more about &lt;code&gt;useEffect&lt;/code&gt; and how that works!&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/1jWS7cCuUXw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How does it work?
&lt;/h2&gt;

&lt;p&gt;You create a functional component and throw some React hook at it that tracks state, can also update it, and it just works.&lt;/p&gt;

&lt;p&gt;Many of us have seen some variation of this example before:&lt;/p&gt;

&lt;h2&gt;
  
  
  One &lt;code&gt;useState&lt;/code&gt;
&lt;/h2&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;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&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;App&lt;/span&gt; &lt;span class="o"&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;useState&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="k"&gt;return &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="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&lt;/span&gt;&lt;span class="dl"&gt;"&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;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;The&lt;/span&gt; &lt;span class="nx"&gt;infamous&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="nx"&gt;example&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&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="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&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="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&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;&amp;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="nx"&gt;span&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0 16px&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;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&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;/span&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="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&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="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&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;&amp;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="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="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;👏 👏 👏 It works!&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvkw3oocepnkrn6btecce.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvkw3oocepnkrn6btecce.gif" alt="Counter figure 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok great, but how does it do that magic? Look at the &lt;code&gt;React.useState&lt;/code&gt; line. It's so easy to read that I never questioned it. I have a destructed array that extracts the &lt;code&gt;count&lt;/code&gt; value and some function called &lt;code&gt;setCount&lt;/code&gt; and it will initialize count with the default value that I passed into &lt;code&gt;useState&lt;/code&gt;. What happens when I add another &lt;code&gt;React.useState&lt;/code&gt; to the picture?&lt;/p&gt;
&lt;h2&gt;
  
  
  Two &lt;code&gt;useState&lt;/code&gt;, ha-ha-ha
&lt;/h2&gt;

&lt;p&gt;Count Dracula anyone?&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;useState&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setMessage&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&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;adder&lt;/span&gt; &lt;span class="o"&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;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&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="nf"&gt;setMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;setMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;You can't go higher than 10&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="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;subtracter&lt;/span&gt; &lt;span class="o"&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;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;&amp;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="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&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="nf"&gt;setMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;setMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;You can't go lower than 1, you crazy&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="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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&lt;/span&gt;&lt;span class="dl"&gt;"&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;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;The&lt;/span&gt; &lt;span class="nx"&gt;infamous&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="nx"&gt;example&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&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="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;subtracter&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;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="nx"&gt;span&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0 16px&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;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&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;/span&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="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;adder&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;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="nx"&gt;p&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;message&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;/p&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="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;Now we are showing a message whenever a user is trying to go outside the bounds of 1 - 10&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fo2ylcqiqnng6rc4w1b00.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fo2ylcqiqnng6rc4w1b00.gif" alt="Counter Figure 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our component, we have two destructured arrays that are using the same &lt;code&gt;React.useState&lt;/code&gt; hook with different default values. Whoa, now we are getting into the magic of it all.&lt;/p&gt;

&lt;p&gt;Alright so lets delete our &lt;code&gt;React&lt;/code&gt; from &lt;code&gt;React.useState&lt;/code&gt; we should get a referenceError saying, "useState is not defined"&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2cx77uybiflvv79nwhys.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2cx77uybiflvv79nwhys.png" alt="Reference error because React is gone"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's implement our own &lt;code&gt;useState&lt;/code&gt; function.&lt;/p&gt;
&lt;h2&gt;
  
  
  Reverse engineering the &lt;code&gt;useState&lt;/code&gt; function
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;useState&lt;/code&gt; function has a value and a function that will set that value&lt;/p&gt;

&lt;p&gt;Something like this:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="o"&gt;=&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="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;state&lt;/span&gt; &lt;span class="o"&gt;=&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;setValue&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;state&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;
&lt;p&gt;We are still getting referenceErrors because we haven't defined &lt;code&gt;setValue&lt;/code&gt;. We know that setValue is a function because of how we use it in &lt;code&gt;useState&lt;/code&gt;&lt;br&gt;
Our count &lt;code&gt;useState&lt;/code&gt;: &lt;code&gt;const [count, setCount] = React.useState(1);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Calling &lt;code&gt;setCount&lt;/code&gt;: &lt;code&gt;setCount(count + 1);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Creating the &lt;code&gt;setValue&lt;/code&gt; function results in no more error but the &lt;code&gt;-&lt;/code&gt; and &lt;code&gt;+&lt;/code&gt; buttons don't work.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="o"&gt;=&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="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;setValue&lt;/span&gt; &lt;span class="o"&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="c1"&gt;// What do we do in here?&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;state&lt;/span&gt; &lt;span class="o"&gt;=&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;setValue&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;state&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;
&lt;p&gt;If we try and change the default value in &lt;code&gt;useState&lt;/code&gt; it will update &lt;code&gt;count&lt;/code&gt; 👍🏽. At least something is working 😂.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fql0xqbggr1b4z4hga9ia.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fql0xqbggr1b4z4hga9ia.gif" alt="Counter figure 3"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Moving on to figuring out what the hell &lt;code&gt;setValue&lt;/code&gt; does.
&lt;/h3&gt;

&lt;p&gt;When we look at &lt;code&gt;setCount&lt;/code&gt; it's doing some sort of value reassignment and then it causes React to rerender. So that is what we are going to do next.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;setValue&lt;/span&gt; &lt;span class="o"&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="c1"&gt;// What do we do in here?&lt;/span&gt;
  &lt;span class="c1"&gt;// Do some assigning&lt;/span&gt;
  &lt;span class="c1"&gt;// Rerender React&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;
&lt;p&gt;We will pass in a new value argument to our &lt;code&gt;setValue&lt;/code&gt; function. &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;setValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newValue&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;// What do we do in here?&lt;/span&gt;
  &lt;span class="c1"&gt;// Do some assigning&lt;/span&gt;
  &lt;span class="c1"&gt;// Rerender React&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;
&lt;p&gt;But what do we do with &lt;code&gt;newValue&lt;/code&gt; within the &lt;code&gt;setValue&lt;/code&gt; function?&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;setValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newValue&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;// Do some assigning&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;newValue&lt;/span&gt; &lt;span class="c1"&gt;// Does this work?&lt;/span&gt;
  &lt;span class="c1"&gt;// Rerender React&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;
&lt;p&gt;&lt;code&gt;value = newValue&lt;/code&gt; makes sense but that does not update the value of the counter. Why? When I &lt;code&gt;console.log&lt;/code&gt; within &lt;code&gt;setValue&lt;/code&gt; and outside of &lt;code&gt;setValue&lt;/code&gt; this is what we see.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnnzm7euilj4or1hqirga.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnnzm7euilj4or1hqirga.gif" alt="Counter does not update when + is clicked"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So After I refresh the page. The count is initialized to 1 and the message is initialized to null, great start. I click the &lt;code&gt;+&lt;/code&gt; button and we see the count value increase to 2, but it does not update count on the screen. 🤔 Maybe I need to manually re-render the browser to update the count?&lt;/p&gt;
&lt;h3&gt;
  
  
  Implement a janky way to manually re-render the browser
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="o"&gt;=&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="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;setValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newValue&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;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newValue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;manualRerender&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;state&lt;/span&gt; &lt;span class="o"&gt;=&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;setValue&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;state&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;manualRerender&lt;/span&gt; &lt;span class="o"&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;rootElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&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;App&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;rootElement&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nf"&gt;manualRerender&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;


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

&lt;/div&gt;
&lt;p&gt;This still doesn't update count in the browser. What the heck? &lt;/p&gt;

&lt;p&gt;I was stuck on this for a little while and now I know why. Let's &lt;code&gt;console.log&lt;/code&gt; state right after we create it.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&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;setValue&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="nf"&gt;log&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Our call to &lt;code&gt;useState&lt;/code&gt; causes the first render, and we get:&lt;br&gt;
&lt;code&gt;[1, setValue()]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And on our second call to &lt;code&gt;useState&lt;/code&gt; we render:&lt;br&gt;
&lt;code&gt;[null, setValue()]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;resulting in:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F53tigt09sbs08tjvs1zo.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F53tigt09sbs08tjvs1zo.png" alt="first render"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To help visualize this a bit better, let's add a render tracker to count how many times we render the screen.&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;let&lt;/span&gt; &lt;span class="nx"&gt;render&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="o"&gt;=&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="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;setValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newValue&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;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newValue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;manualRerender&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;state&lt;/span&gt; &lt;span class="o"&gt;=&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;setValue&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="nx"&gt;render&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="nf"&gt;log&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;state&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;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbns9gvs2lcvjkh68mnrn.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbns9gvs2lcvjkh68mnrn.gif" alt="Track renders when useState is called"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How does our &lt;code&gt;setValue&lt;/code&gt; function know which value to update? It doesn't, therefore we need a way to track it. You can use an array or an object to do this. I choose the red pill of objects.&lt;/p&gt;

&lt;p&gt;Outside of &lt;code&gt;useState&lt;/code&gt; function, we are going to create an object called &lt;code&gt;states&lt;/code&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const states = {}


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

&lt;/div&gt;
&lt;p&gt;Within the &lt;code&gt;useState&lt;/code&gt; function initialize the &lt;code&gt;states&lt;/code&gt; object. Let's use the bracket notation to assign the key/value pair.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;states[++render] = state&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I am also going to create another variable called &lt;code&gt;id&lt;/code&gt; that will store the render value so we can take out the &lt;code&gt;++render&lt;/code&gt; within the brackets.&lt;/p&gt;

&lt;p&gt;You should have something that looks like this:&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;let&lt;/span&gt; &lt;span class="nx"&gt;render&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="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;states&lt;/span&gt; &lt;span class="o"&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;useState&lt;/span&gt; &lt;span class="o"&gt;=&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="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;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="nx"&gt;render&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;setValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newValue&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;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newValue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;manualRerender&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;state&lt;/span&gt; &lt;span class="o"&gt;=&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;setValue&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="nx"&gt;states&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;states&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;state&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;What does our &lt;code&gt;states&lt;/code&gt; object look like? &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

states = {
  0: [1, setValue],
  1: [null, setValue]
}


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

&lt;/div&gt;
&lt;p&gt;So now when we click the add and subtract buttons we get... nothing again. Oh right because &lt;code&gt;value = newValue&lt;/code&gt; still isn't doing anything.&lt;/p&gt;

&lt;p&gt;But there is something that is happening. If you look at the console you will see that every time we click on one of the buttons it will keep adding the same arrays to our &lt;code&gt;states&lt;/code&gt; object but &lt;code&gt;count&lt;/code&gt; isn't incrementing and message is still null.&lt;/p&gt;

&lt;p&gt;So &lt;code&gt;setValue&lt;/code&gt; needs to go look for &lt;code&gt;value&lt;/code&gt;, then assign the &lt;code&gt;newValue&lt;/code&gt; to &lt;code&gt;value&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;setValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newValue&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;states&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;id&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;newValue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;manualRerender&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 want to make sure we are only updating keys: 0 and 1 since those will be our two &lt;code&gt;useState&lt;/code&gt; locations.&lt;/p&gt;

&lt;p&gt;So head down to the &lt;code&gt;manualRerender&lt;/code&gt; function and add a call to &lt;code&gt;render&lt;/code&gt; and reassign it to -1&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;manualRerender&lt;/span&gt; &lt;span class="o"&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;render&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="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rootElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&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;App&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;rootElement&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;We do this because every time we call setValue it will call the &lt;code&gt;manualRerender&lt;/code&gt; function setting &lt;code&gt;render&lt;/code&gt; back to -1&lt;/p&gt;

&lt;p&gt;Lastly, we will add a check to see if the object exists. If it does then we will just return the object.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

if (states[id]) return states[id];


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

&lt;/div&gt;
&lt;p&gt;Now we work again!&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fte6m7hnuoou0530ep42g.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fte6m7hnuoou0530ep42g.gif" alt="Counter working"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Phew. That was a lot to process and this is just a very simplistic approach to &lt;code&gt;useState&lt;/code&gt;. There is a ton more that happens behind the scenes, but at least we have a rough idea of how it works and we demystified it a bit.&lt;/p&gt;

&lt;p&gt;Take a look at all the code and try and make a mental model of how it all works.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/react-hooks-deconstructed-mj5tk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Hope this helps 😊 &lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What interview questions have you been asked?</title>
      <dc:creator>Rembrandt Reyes (He/Him)</dc:creator>
      <pubDate>Fri, 07 Aug 2020 03:48:36 +0000</pubDate>
      <link>https://dev.to/rembrandtreyes/what-interview-questions-have-you-been-asked-45gn</link>
      <guid>https://dev.to/rembrandtreyes/what-interview-questions-have-you-been-asked-45gn</guid>
      <description>&lt;p&gt;If you want to get specific great! If not just a general overview of your interview process will be fine.&lt;/p&gt;

&lt;p&gt;How many rounds of interviews?&lt;br&gt;
What kind of behavioral questions were you asked?&lt;br&gt;
What type of technical questions were you asked?&lt;br&gt;
Were you given a take-home project?&lt;br&gt;
How many people did you interact with during your interviews?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>career</category>
    </item>
    <item>
      <title>Let's solve LeetCode! Fibonacci Number</title>
      <dc:creator>Rembrandt Reyes (He/Him)</dc:creator>
      <pubDate>Wed, 05 Aug 2020 04:09:59 +0000</pubDate>
      <link>https://dev.to/rembrandtreyes/let-s-solve-leetcode-fibonacci-number-4cpj</link>
      <guid>https://dev.to/rembrandtreyes/let-s-solve-leetcode-fibonacci-number-4cpj</guid>
      <description>&lt;h1&gt;
  
  
  Problem 509 - &lt;a href="https://leetcode.com/problems/fibonacci-number/"&gt;Fibonacci Number&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;F(0) = 0,   F(1) = 1
F(N) = F(N - 1) + F(N - 2), for N &amp;gt; 1.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Given &lt;code&gt;N&lt;/code&gt;, calculate &lt;code&gt;F(N)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This problem is a great introduction to recursion and a little fun concept called dynamic programming (DP).&lt;/p&gt;

&lt;h2&gt;
  
  
  Conceptual Overview
&lt;/h2&gt;

&lt;p&gt;In mathematics, the Fibonacci numbers form a sequence called the Fibonacci sequence, such that each number is the sum of the two preceding ones starting from 0 and 1. &lt;/p&gt;

&lt;p&gt;For example: 0, 1, 1, 2, 3, 5, ...&lt;/p&gt;

&lt;p&gt;So how do we solve this? I mentioned earlier that this problem is an introduction to recursion and DP. It is, but there are a few ways we can solve this problem.&lt;/p&gt;

&lt;p&gt;If you want to learn more about Dynamic Programming, check out &lt;a href="https://www.youtube.com/watch?v=OQ5jsbhAv_M&amp;amp;list=PLUl4u3cNGP61Oq3tWYp6V_F-5jb5L2iHb&amp;amp;index=19"&gt;Dynamic Programming I: Fibonacci, Shortest Paths&lt;/a&gt; from MIT OpenCourseWare.&lt;/p&gt;

&lt;p&gt;So there are a few solutions:&lt;br&gt;
1) Recursion&lt;br&gt;
2) Recursion with DP&lt;br&gt;
3) Iteratively&lt;/p&gt;

&lt;p&gt;Each with different time and space complexities.&lt;/p&gt;
&lt;h2&gt;
  
  
  Coding walkthrough
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Recursion only
&lt;/h3&gt;

&lt;p&gt;Any function that uses Recursion you must remember that there needs to be a base condition to stop the recursion. If the base case is not reached or defined then there will be stack overflow due to memory limitations.&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="cm"&gt;/**
 * @param {number} N
 * @return {number}
 */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fib&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;N&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;2&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;N&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// base condition&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt; &lt;span class="o"&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="nx"&gt;fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;N&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="c1"&gt;// recursion&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pretty straight forward, there's a base condition that will stop the recursion when it evaluates to true.&lt;/p&gt;

&lt;h4&gt;
  
  
  Time &amp;amp; Space Complexity
&lt;/h4&gt;

&lt;p&gt;Time: O(2^N) &amp;amp; Space: O(N)&lt;/p&gt;

&lt;h3&gt;
  
  
  Memoized dynamic programming algorithm
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * @param {number} N
 * @return {number}
 */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fib&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;N&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;memo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="nx"&gt;memo&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="mi"&gt;0&lt;/span&gt; &lt;span class="c1"&gt;// Given&lt;/span&gt;
    &lt;span class="nx"&gt;memo&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="mi"&gt;1&lt;/span&gt; &lt;span class="c1"&gt;// Given&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;N&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;memo&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;memo&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;// Base condition&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;  &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;memo&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;N&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="nx"&gt;fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Memoize results&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;memo&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;N&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;Whenever we compute a Fibonacci number we put it into the hash table. We do this to "store" or memorize the value so we do not have to do the calculation again. We can look up the key-value in constant time.&lt;/p&gt;

&lt;h4&gt;
  
  
  Time &amp;amp; Space Complexity
&lt;/h4&gt;

&lt;p&gt;This would be considered a top-down approach&lt;br&gt;
Time: O(N) &amp;amp; Space: O(N)&lt;/p&gt;

&lt;h3&gt;
  
  
  Iterative approach
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fib&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;N&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;lastTwo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&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;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&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;N&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&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;return&lt;/span&gt; &lt;span class="nx"&gt;N&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;N&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&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="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;counter&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;N&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;nextFib&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;lastTwo&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;lastTwo&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="nx"&gt;lastTwo&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;lastTwo&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="nx"&gt;lastTwo&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;nextFib&lt;/span&gt;
        &lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="o"&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;lastTwo&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;lastTwo&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="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Time &amp;amp; Space Complexity
&lt;/h4&gt;

&lt;p&gt;Time: O(N) &amp;amp; Space: O(1)&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>javascript</category>
    </item>
    <item>
      <title>My top terminal commands</title>
      <dc:creator>Rembrandt Reyes (He/Him)</dc:creator>
      <pubDate>Mon, 03 Aug 2020 20:37:43 +0000</pubDate>
      <link>https://dev.to/rembrandtreyes/my-top-terminal-commands-19m2</link>
      <guid>https://dev.to/rembrandtreyes/my-top-terminal-commands-19m2</guid>
      <description>&lt;p&gt;I was recently watching a video that was walking beginners through terminal commands and they listed over 50 commands that you should use. 50!? Who uses more than 10 terminal commands?&lt;/p&gt;

&lt;p&gt;The ones that I use (off the top of my head)&lt;/p&gt;

&lt;h3&gt;
  
  
  1) &lt;code&gt;pwd&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The command &lt;code&gt;pwd&lt;/code&gt; stands for "print working directory" which gives your current location in terminal&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HbKR2ygQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n7irrwsoapkjufi1qmu8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HbKR2ygQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n7irrwsoapkjufi1qmu8.png" alt="pwd" width="880" height="660"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2) &lt;code&gt;cd&lt;/code&gt; &lt;code&gt;directory&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The command &lt;code&gt;cd&lt;/code&gt; stands for "change directory" which allows you to navigate through the terminal.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0lLbcaH1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1ynrh1mprbe9trkus8oc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0lLbcaH1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1ynrh1mprbe9trkus8oc.png" alt="cd" width="880" height="660"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3) &lt;code&gt;ls&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The command &lt;code&gt;ls&lt;/code&gt; will list all the computer files in your current directory.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z6mnZngp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/umrv91gm0y81s95lv1gz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z6mnZngp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/umrv91gm0y81s95lv1gz.png" alt="ls" width="880" height="660"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4) &lt;code&gt;mkdir&lt;/code&gt; &lt;code&gt;folder&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The command &lt;code&gt;mkdir&lt;/code&gt; will create a new folder in your current directory.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IG_7JqR7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/72q31138jd99cm8uhndy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IG_7JqR7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/72q31138jd99cm8uhndy.png" alt="mkdir" width="880" height="660"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5) &lt;code&gt;clear&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The command &lt;code&gt;clear&lt;/code&gt; will... you guessed it, clear your terminal.&lt;/p&gt;

&lt;h3&gt;
  
  
  6) &lt;code&gt;🐈&lt;/code&gt; aka &lt;code&gt;cat&lt;/code&gt; file
&lt;/h3&gt;

&lt;p&gt;The command &lt;code&gt;cat&lt;/code&gt; will return the contents of a file.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WZkalsJb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xdj7cfgzwc181c1vzbtb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WZkalsJb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xdj7cfgzwc181c1vzbtb.png" alt="cat" width="880" height="660"&gt;&lt;/a&gt;&lt;br&gt;
If you &lt;code&gt;cat&lt;/code&gt; command a directory it will let you know that as well.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iB3VHIUx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1v2kcpchbjsodwbijnem.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iB3VHIUx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1v2kcpchbjsodwbijnem.png" alt="catDir" width="880" height="660"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  7) &lt;code&gt;touch&lt;/code&gt; &lt;code&gt;file&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The command &lt;code&gt;touch&lt;/code&gt; file will create a new file in your current directory.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9OGln66e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/je1dsyg74sdsqyerh761.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9OGln66e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/je1dsyg74sdsqyerh761.png" alt="touch" width="880" height="660"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  8) &lt;code&gt;rm&lt;/code&gt; &lt;code&gt;file&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The command &lt;code&gt;rm&lt;/code&gt; file will remove the file from your current directory&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eyqWeTtt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/q4lgot9ri3mvdw83j1b2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eyqWeTtt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/q4lgot9ri3mvdw83j1b2.png" alt="rm" width="880" height="660"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are some special options that you can pass into some of these commands but for now, the basics are all that is needed to be a hacker! &lt;/p&gt;

&lt;p&gt;Some honorable mentions - these are commands that I use here and there. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;mv&lt;/code&gt; - move files or rename files&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sudo&lt;/code&gt; - "SuperUser Do", this enables admin/root permissions, only use this if you know what you are doing&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;grep&lt;/code&gt; - search for something in a file&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ping&lt;/code&gt; - check your connectivity status to a server.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;echo&lt;/code&gt; - used to move data into a file&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>beginners</category>
    </item>
    <item>
      <title>Part 8 - Trying to get eSlayers to MVP</title>
      <dc:creator>Rembrandt Reyes (He/Him)</dc:creator>
      <pubDate>Mon, 03 Aug 2020 02:31:51 +0000</pubDate>
      <link>https://dev.to/rembrandtreyes/part-8-trying-to-get-eslayers-to-mvp-1hd5</link>
      <guid>https://dev.to/rembrandtreyes/part-8-trying-to-get-eslayers-to-mvp-1hd5</guid>
      <description>&lt;p&gt;There are so many features that I want to get out before I launch this site but I need to remind myself that those are all things that can come later in the project's life. I need to stay to true to the MVP that I set out for this project&lt;/p&gt;

&lt;p&gt;My checklist of things I wanted&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Search for a summoner&lt;/li&gt;
&lt;li&gt;Display top players in TFT&lt;/li&gt;
&lt;li&gt;Summoner stats&lt;/li&gt;
&lt;li&gt;Summoner match history&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The last piece of data that I am working on is the top players for TFT. I want to display a list of players on the home page that will show the top 20 players in Challenger.&lt;/p&gt;

&lt;p&gt;There are a couple of tricky things to this list that I have to consider. The API returns all the players in Challenger in no particular order. The list is an array of objects with 100 entries. Since I am trying to return only the top 20 players I will have to do some logic that will sort the players based on their League Points and filter out the rest.&lt;/p&gt;

&lt;p&gt;This is what my &lt;code&gt;index.tsx&lt;/code&gt; looks like for now.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R6fyyKa8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7lfrw8s4cb4vn5bre37j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R6fyyKa8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7lfrw8s4cb4vn5bre37j.png" alt="index component"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And I get my top 20 players from Challenger on the home page&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FCA6Mv6t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/qu7ik7ojqwiyhsoiycis.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FCA6Mv6t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/qu7ik7ojqwiyhsoiycis.png" alt="Top 20"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Awesome! So now that I am "finished" with the MVP data. I am going to move on to styling the pages.&lt;/p&gt;

&lt;p&gt;Next up I will be deciding on a color scheme and then start on the layout of the website.&lt;/p&gt;

</description>
      <category>react</category>
      <category>typescript</category>
    </item>
    <item>
      <title>eSlayers part 7 - fetching more data for math history</title>
      <dc:creator>Rembrandt Reyes (He/Him)</dc:creator>
      <pubDate>Sun, 02 Aug 2020 01:09:42 +0000</pubDate>
      <link>https://dev.to/rembrandtreyes/eslayers-part-7-fetching-more-data-for-math-history-2c43</link>
      <guid>https://dev.to/rembrandtreyes/eslayers-part-7-fetching-more-data-for-math-history-2c43</guid>
      <description>&lt;p&gt;Last post I was working on fetching data and trying to get some information to display for player match history. Now that I can fetch data from the match API I am going through and pulling all relevant data for match history&lt;/p&gt;

&lt;p&gt;So far I have&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Player name&lt;/li&gt;
&lt;li&gt;Placement&lt;/li&gt;
&lt;li&gt;Gold left&lt;/li&gt;
&lt;li&gt;In-game level&lt;/li&gt;
&lt;li&gt;Players eliminated&lt;/li&gt;
&lt;li&gt;Trait of units used

&lt;ul&gt;
&lt;li&gt;Trait name&lt;/li&gt;
&lt;li&gt;Number of units&lt;/li&gt;
&lt;li&gt;Tier style&lt;/li&gt;
&lt;li&gt;Tier of trait&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Units

&lt;ul&gt;
&lt;li&gt;Unit name&lt;/li&gt;
&lt;li&gt;Tier&lt;/li&gt;
&lt;li&gt;Items&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is what my &lt;code&gt;Match.tsx&lt;/code&gt; component looks like now&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ocvlDG7x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dmzrvr05jyxca20fs5od.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ocvlDG7x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dmzrvr05jyxca20fs5od.png" alt="Match Component"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And how it looks in localhost&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oc5gePWP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dd1jdkqom4lvgws9ty9n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oc5gePWP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dd1jdkqom4lvgws9ty9n.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So now that I have match history I want to pull more information related to the summoner. So in my case, I would like to pull some stats for Rjeezy. &lt;/p&gt;

&lt;p&gt;Here are the data points I am looking to get for the summoner:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Average placement&lt;/li&gt;
&lt;li&gt;Trait stats for the last 20 games&lt;/li&gt;
&lt;li&gt;Most used units&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So next up I will create some logic that will filter out all players besides the summoner so I can get access to summoner specific data for the data points I am trying to show.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>nextjs</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Let's solve LeetCode - Is Subsequence</title>
      <dc:creator>Rembrandt Reyes (He/Him)</dc:creator>
      <pubDate>Fri, 31 Jul 2020 05:56:37 +0000</pubDate>
      <link>https://dev.to/rembrandtreyes/let-s-solve-leetcode-is-subsequence-46j3</link>
      <guid>https://dev.to/rembrandtreyes/let-s-solve-leetcode-is-subsequence-46j3</guid>
      <description>&lt;h1&gt;
  
  
  Problem 392 - &lt;a href="https://leetcode.com/problems/is-subsequence/"&gt;Is Subsequence&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Given a string &lt;code&gt;s&lt;/code&gt; and a string &lt;code&gt;t&lt;/code&gt;, check if &lt;code&gt;s&lt;/code&gt; is a subsequence of &lt;code&gt;t&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, &lt;code&gt;"ace"&lt;/code&gt; is a subsequence of &lt;code&gt;"abcde"&lt;/code&gt; while &lt;code&gt;"aec"&lt;/code&gt; is not).&lt;/p&gt;

&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input: s = "abc", t = "ahbgdc"
Output: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input: s = "axc", t = "ahbgdc"
Output: false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conceptual Overview
&lt;/h3&gt;

&lt;p&gt;Since we want to check if &lt;code&gt;s&lt;/code&gt; is a subsequence of &lt;code&gt;t&lt;/code&gt; we will want to check every character of &lt;code&gt;s&lt;/code&gt; against &lt;code&gt;t&lt;/code&gt; and if a character at &lt;code&gt;s&lt;/code&gt; matches a character in &lt;code&gt;t&lt;/code&gt; (in order) then we can move onto the next character in &lt;code&gt;s&lt;/code&gt; and do the check all over again.&lt;/p&gt;

&lt;p&gt;Looking at the example above let's run through a couple of iterations. In ECMAScript 5 we can treat the string as an array-like object, where individual characters correspond to a numerical index.&lt;/p&gt;

&lt;p&gt;1) At s[0] = a; t[0] = a; does s[0] === t[0]? Yes, move to the next character in &lt;code&gt;s&lt;/code&gt; and &lt;code&gt;t&lt;/code&gt;&lt;br&gt;
2) At s[1] = b; t[1] = h; does s[1] === t[0]? No, move to the next character in &lt;code&gt;t&lt;/code&gt;&lt;br&gt;
3) At s[1] = b; t[2] = b; does s[1] === t[2]? Yes, move to the next character in &lt;code&gt;s&lt;/code&gt; and &lt;code&gt;t&lt;/code&gt;&lt;br&gt;
...&lt;br&gt;
6) At s[2] = c; t[5] = c; does s[3] === t[5]? Yes, and since we went through the length of &lt;code&gt;s&lt;/code&gt; we found &lt;code&gt;s&lt;/code&gt; to be a subsequence of &lt;code&gt;t&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Code
&lt;/h3&gt;

&lt;p&gt;While-loop variation&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="cm"&gt;/**
 * @param {string} s
 * @param {string} t
 * @return {boolean}
 */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isSubsequence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;t&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&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;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sPointer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;tPointer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&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;sPointer&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;s&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;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;tPointer&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;t&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="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;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;sPointer&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;tPointer&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="nx"&gt;sPointer&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;

        &lt;span class="nx"&gt;tPointer&lt;/span&gt;&lt;span class="o"&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;sPointer&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;s&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For-loop variation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isSubsequence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;t&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&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;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sPointer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&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;t&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;sPointer&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;t&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="nx"&gt;sPointer&lt;/span&gt;&lt;span class="o"&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;sPointer&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;s&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In both code solutions, we need to keep track of our position in each string so we use pointers to help with that.&lt;/p&gt;

&lt;h3&gt;
  
  
  Time &amp;amp; Space Complexity
&lt;/h3&gt;

&lt;p&gt;Time: O(n) - where n is the length of the array&lt;br&gt;
Space: O(1)&lt;br&gt;
Both variations have the same time and space complexity&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Let's solve LeetCode! Two Sum</title>
      <dc:creator>Rembrandt Reyes (He/Him)</dc:creator>
      <pubDate>Tue, 28 Jul 2020 06:05:58 +0000</pubDate>
      <link>https://dev.to/rembrandtreyes/let-s-solve-leetcode-two-sum-7lh</link>
      <guid>https://dev.to/rembrandtreyes/let-s-solve-leetcode-two-sum-7lh</guid>
      <description>&lt;h1&gt;
  
  
  &lt;a href="https://leetcode.com/problems/two-sum/"&gt;Two Sum: Easy&lt;/a&gt;
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Given an array of integers, return indices of the two numbers such that they add up to a specific target.&lt;/p&gt;

&lt;p&gt;You may assume that each input would have exactly one solution, and you may not use the same element twice. &lt;/p&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Given nums = [2, 7, 11, 15], target = 18,

Because nums[1] + nums[2] = 7 + 11 = 18,
return [1, 2].
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conceptual Overview
&lt;/h3&gt;

&lt;p&gt;Before we get to the solution lets think about this conceptually. Looking at the array from our example we would need to find the pair of indices that add up to 18.&lt;/p&gt;

&lt;h4&gt;
  
  
  Possible Solution #1
&lt;/h4&gt;

&lt;p&gt;One way of finding the indices would be to iterate through the array with two for-loops. Create a for-loop that will traverse the array and nest a second for-loop that will traverse the rest of the array at an index of +1 to the first loop.&lt;/p&gt;

&lt;h5&gt;
  
  
  Time &amp;amp; Space Complexity
&lt;/h5&gt;

&lt;p&gt;O(n^2) Time &amp;amp; O(1) | Two for loops with a constant lookup&lt;/p&gt;

&lt;h4&gt;
  
  
  Possible Solution #2
&lt;/h4&gt;

&lt;p&gt;A solution that is faster but will require more space will be making use of hash tables or more simply using an object.&lt;/p&gt;

&lt;p&gt;When we use a hash table to store values we have access to constant lookup which makes this solution much quicker than the first. So as we iterate through the array we will be checking the hash table to see if it has the value we are looking for that adds up to target. Let's write some arithmetic&lt;/p&gt;

&lt;p&gt;X1 + X2 = target&lt;br&gt;
Where:&lt;br&gt;
target = 18&lt;br&gt;
X1 = current value in for-loop&lt;br&gt;
Find X2&lt;br&gt;
X2 = target - X1&lt;/p&gt;

&lt;p&gt;So as we loop through the array we are storing values to the hash table and checking to see if X2 exists in the has table. If X2 exists then we return indices of [X1, X2]&lt;/p&gt;

&lt;h5&gt;
  
  
  Time &amp;amp; Space Complexity
&lt;/h5&gt;

&lt;p&gt;O(n) Time &amp;amp; O(n) Space | One for-loop and storing data to a hash table iterating through the array once&lt;/p&gt;

&lt;h3&gt;
  
  
  Solutions
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Solution #1 O(n^2) Time &amp;amp; O(1) Space
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;twoSum&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="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;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="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="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="nx"&gt;j&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;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="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;i&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="p"&gt;]&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="k"&gt;return&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="nx"&gt;j&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="p"&gt;[]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Solution #2 O(n) Time &amp;amp; O(n) Space
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;twoSum&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="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;hash&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;hash&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="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="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;undefined&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="nx"&gt;hash&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="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="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="p"&gt;}&lt;/span&gt;

        &lt;span class="nx"&gt;hash&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;i&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&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;And there you have it! A couple of solutions for Two Sum. I would love to see what solutions you all came up with. See you all in the discussions :D&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>eSlayers part 6 - fetching matches... finally</title>
      <dc:creator>Rembrandt Reyes (He/Him)</dc:creator>
      <pubDate>Fri, 24 Jul 2020 05:25:51 +0000</pubDate>
      <link>https://dev.to/rembrandtreyes/eslayers-part-6-fetching-matches-finally-31ef</link>
      <guid>https://dev.to/rembrandtreyes/eslayers-part-6-fetching-matches-finally-31ef</guid>
      <description>&lt;p&gt;Finally made it to fetching some sort of match history. There is definitely a lot of refactoring that needs to be done, but for now, I am pretty content with what I got.&lt;/p&gt;

&lt;h2&gt;
  
  
  Things I completed today
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Modified &lt;code&gt;server.ts&lt;/code&gt; to add an additional proxy route. &lt;/li&gt;
&lt;li&gt;Added a &lt;code&gt;Match.tsx&lt;/code&gt; component which returns game_date and participants.&lt;/li&gt;
&lt;li&gt;Added a &lt;code&gt;Participant.tsx&lt;/code&gt; component which will return a summoner's name from their &lt;code&gt;puuid&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Modified &lt;code&gt;Summoner.tsx&lt;/code&gt; to test newly fetched data.&lt;/li&gt;
&lt;li&gt;Modify &lt;code&gt;fetchLeague.ts&lt;/code&gt; URL to the updated proxy API.&lt;/li&gt;
&lt;li&gt;Modify &lt;code&gt;fetchSummoner.ts&lt;/code&gt; URL to the updated proxy API and add in a new function to fetch summoner based on use &lt;code&gt;puuid&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Add a new fetch to get data of a single TFT match.&lt;/li&gt;
&lt;li&gt;Add a new fetch to get an array of matches.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Pain points
&lt;/h2&gt;

&lt;p&gt;There were a lot of issues at first because I was trying to do some data manipulation on stuff that was not fully fetched yet. I thought I was doing things right with &lt;code&gt;useSWR&lt;/code&gt; conditional fetching, but I just fooled myself, sorta. Lot's of &lt;code&gt;console.logs&lt;/code&gt; and chrome debugger to see what was happening and where my code was breaking. I landed on a solution that seems to work 100% of the time now. I think once I start breaking things down even further the pieces will start to come together and things will play nicer with each other.&lt;/p&gt;

&lt;h2&gt;
  
  
  For the future
&lt;/h2&gt;

&lt;p&gt;At some point, I am going to want to save this data to some sort of state manager. Deciding between redux or React.Context. I am also wondering if this app will be possible with just &lt;code&gt;useState&lt;/code&gt;. I don't have a clear picture yet since I can do everything with fetching. Once I get to a "finalized" state of data that I am going to display I will decide on a state manager.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>javascript</category>
      <category>html</category>
    </item>
    <item>
      <title>eSlayers part 5 - data fetching strikes back</title>
      <dc:creator>Rembrandt Reyes (He/Him)</dc:creator>
      <pubDate>Thu, 23 Jul 2020 04:41:59 +0000</pubDate>
      <link>https://dev.to/rembrandtreyes/eslayers-part-5-data-fetching-strikes-back-3695</link>
      <guid>https://dev.to/rembrandtreyes/eslayers-part-5-data-fetching-strikes-back-3695</guid>
      <description>&lt;p&gt;So I went back to working on my application, and my website broke. I was trying to fetch my summoner name and it would throw an error when it tried fetching data for my rankings.&lt;/p&gt;

&lt;p&gt;I did some digging and it turns out the data that was being returned from the first fetch was not finished so by the time it got to the second fetch it would error out. Since I am using &lt;code&gt;useSWR&lt;/code&gt; I had to read the docs to see if there was anything that I could use that would allow me to fetch data dependent on the first fetch.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://swr.vercel.app/docs/conditional-fetching"&gt;Conditional Fetching&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;useSWR&lt;/code&gt; allows you to fetch data dependent on whatever you want. In my case, I need to make my fetch dependent on the summoner name and summoner ID being passed into my fetches.&lt;/p&gt;

&lt;p&gt;I refactored some of my code so now I can reuse fetching summoner and fetching league&lt;/p&gt;

&lt;p&gt;&lt;code&gt;fetchSummoner.ts&lt;/code&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R2V05JH---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/195akud45n1scnbjbgdb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R2V05JH---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/195akud45n1scnbjbgdb.png" alt="Fetch Summoner" width="880" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;fetchLeague.ts&lt;/code&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FZDNGqVf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zovni6m1ygrg6wygs1qa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FZDNGqVf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zovni6m1ygrg6wygs1qa.png" alt="Fetch League" width="880" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Summoner.tsx&lt;/code&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Knsx_sRU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/45u52zy64wfijqyl3zno.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Knsx_sRU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/45u52zy64wfijqyl3zno.png" alt="Summoner Component" width="880" height="1023"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that I figured that headache out I can move on to fetching match history.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How do you Open-Source with a full-time job? and work on side projects?</title>
      <dc:creator>Rembrandt Reyes (He/Him)</dc:creator>
      <pubDate>Fri, 17 Jul 2020 04:46:01 +0000</pubDate>
      <link>https://dev.to/rembrandtreyes/how-do-you-open-source-with-a-full-time-job-and-work-on-side-projects-556h</link>
      <guid>https://dev.to/rembrandtreyes/how-do-you-open-source-with-a-full-time-job-and-work-on-side-projects-556h</guid>
      <description>&lt;p&gt;I have been asked these questions a few times now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Short Answer
&lt;/h2&gt;

&lt;p&gt;"Spending a little time on each as much as possible."&lt;/p&gt;

&lt;p&gt;But it goes a little deeper than that&lt;/p&gt;

&lt;h2&gt;
  
  
  Long Answer
&lt;/h2&gt;

&lt;p&gt;I think right now I can maximize my time because I am remote and I do not have to spend 20, 40, or 60+ minutes commuting to work. That allows me to channel some of that time into open source and side projects. My current company is also based in Boston and I currently live in San Francisco so my 10 - 5 is actually 7 - 2.&lt;/p&gt;

&lt;h3&gt;
  
  
  My weekly schedule
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Wake up around 6:30 AM&lt;/li&gt;
&lt;li&gt;Check-in and stand up 7 AM&lt;/li&gt;
&lt;li&gt;Do a bunch of work-related stuff.&lt;/li&gt;
&lt;li&gt;Skip lunch to continue working or read some docs.&lt;/li&gt;
&lt;li&gt;Clock out around 2 PM and recap with my team what I did for the day.&lt;/li&gt;
&lt;li&gt;Check issues from a couple of OSS and see if there is something that I can work on &lt;em&gt;or&lt;/em&gt; continue working on a ticket that I am assigned to (1 - 2 hours)&lt;/li&gt;
&lt;li&gt;Work on my side project (1 - 2 hours)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I try to put a hard cap on work by 6 - 7 PM because I also have a family and I gotta eat 😅.&lt;/p&gt;

&lt;p&gt;During the weekends I don't always get to OSS or side projects, but if I do have time on the weekends I do a similar 50/50 split so I can maximize my time on each. And if my time is limited I will probably study something related to coding instead. It's honestly hard for me to commit all this time to code. I am exhausted all the time, but I know the grid is worth it. Coding was something that was hard for me to enjoy until I started to understand it better. Now I push myself to code every day, I want to code every day. So 10 - 12 hour days dedicated to code. It's a lot, so do whatever you think is possible for you. Some think this is a sprint, some think this is a marathon. I would say it's a bit of both, so pace yourselves. We all get to the finish line eventually.&lt;/p&gt;

</description>
      <category>opensource</category>
    </item>
  </channel>
</rss>
