<?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: Byte Sized</title>
    <description>The latest articles on DEV Community by Byte Sized (@nspired).</description>
    <link>https://dev.to/nspired</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%2F714393%2F8f8ce9ee-ab6f-40d8-9975-e44efa02178a.png</url>
      <title>DEV Community: Byte Sized</title>
      <link>https://dev.to/nspired</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nspired"/>
    <language>en</language>
    <item>
      <title>The Inspector 🔎: A better way to test your code</title>
      <dc:creator>Byte Sized</dc:creator>
      <pubDate>Sun, 28 Nov 2021 21:42:19 +0000</pubDate>
      <link>https://dev.to/nspired/the-inspector-3h8g</link>
      <guid>https://dev.to/nspired/the-inspector-3h8g</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wyrHZjkN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n1o376zs1yik6dq9lrqn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wyrHZjkN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n1o376zs1yik6dq9lrqn.png" alt="Image description" width="880" height="631"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use this Github Action to surface test errors sooner and develop faster! This action currently only supports JavaScript projects but we look forward to expanding in the future.&lt;/p&gt;

&lt;p&gt;What the action does:&lt;/p&gt;

&lt;p&gt;Creates PR comment with failing test, which includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Link failing test &lt;/li&gt;
&lt;li&gt;Direct link to source code where the error is coming from&lt;/li&gt;
&lt;li&gt;Stacktrace &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  My Workflow
&lt;/h3&gt;

&lt;p&gt;This project is using the Sticky Pull Request Comments github action repo: &lt;br&gt;
&lt;a href="https://github.com/marocchino/sticky-pull-request-comment"&gt;https://github.com/marocchino/sticky-pull-request-comment&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Submission Category:
&lt;/h3&gt;

&lt;p&gt;DIY Deployments&lt;/p&gt;

&lt;h3&gt;
  
  
  Yaml File or Link to Code
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/nspired-tech/hackathon-the-inspector/blob/main/.github/workflows/test.yml"&gt;https://github.com/nspired-tech/hackathon-the-inspector/blob/main/.github/workflows/test.yml&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Additional Resources / Info
&lt;/h3&gt;

</description>
      <category>actionshackathon21</category>
      <category>javascript</category>
      <category>opensource</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Introducing: Tunnel Vision....</title>
      <dc:creator>Byte Sized</dc:creator>
      <pubDate>Sun, 14 Nov 2021 23:39:16 +0000</pubDate>
      <link>https://dev.to/nspired/introducing-tunnel-vision-4207</link>
      <guid>https://dev.to/nspired/introducing-tunnel-vision-4207</guid>
      <description>&lt;p&gt;While coming up with an idea for Actions Hackathon 2021, We started thinking about all the things on our "wish list" for CI/CD. The biggest wish has been to have an easier way to surface errors within our unit tests. &lt;/p&gt;

&lt;p&gt;Most of you are familiar with other CI/CD tools and know that when a failing test occurs you have to scroll through this large wall of text just to find the failing test. And in most cases, you don't know exactly where to look...&lt;/p&gt;

&lt;p&gt;Here is the inspiration behind our hackathon idea! We will be enabling the CI/CD pipeline within Github Actions to surface the exact error and links to send you directly to it. We call this tunnel vision! This feature will allow you to move even more quickly while in the development phase. &lt;/p&gt;

&lt;p&gt;Stay tuned for the project details and submission🔥&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>actionshackathon21</category>
      <category>actions</category>
      <category>testing</category>
    </item>
    <item>
      <title>Reduce Vs For-Loop</title>
      <dc:creator>Byte Sized</dc:creator>
      <pubDate>Tue, 09 Nov 2021 22:19:28 +0000</pubDate>
      <link>https://dev.to/nspired/reduce-vs-for-loop-4eab</link>
      <guid>https://dev.to/nspired/reduce-vs-for-loop-4eab</guid>
      <description>&lt;p&gt;Are you interested in more tech content? Check us out on Twitter &lt;a href="https://twitter.com/@nspiredTech" rel="noopener noreferrer"&gt;@nspiredTech&lt;/a&gt;!&lt;/p&gt;




&lt;p&gt;I was working through some JavaScript Functional Programming examples when I came across the &lt;code&gt;reduce&lt;/code&gt; method. By definition &lt;code&gt;reduce&lt;/code&gt; is used to iterate through an array and condense it into one value.&lt;/p&gt;

&lt;p&gt;This caused me to wonder what was the programmatic difference between &lt;code&gt;reduce&lt;/code&gt; and a traditional &lt;code&gt;for&lt;/code&gt;-loop?&lt;/p&gt;

&lt;p&gt;Here is an example of the reduce method in action:&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;let&lt;/span&gt; &lt;span class="nx"&gt;singleVal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;previousVal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentVal&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;previousVal&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;currentVal&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The pattern above stores the return value from the reduce method. The reduce method receives a callback function with the parameters &lt;code&gt;previousVal&lt;/code&gt; and &lt;code&gt;currentVal&lt;/code&gt;. As the array is being iterated each elements is being added together.&lt;/p&gt;

&lt;p&gt;Here is the same input but with a &lt;code&gt;for&lt;/code&gt;-loop&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;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;array&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="nx"&gt;singleVal&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&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;The same result is achieved with a &lt;code&gt;for&lt;/code&gt;-loop. For each pass, the element or &lt;code&gt;array[i]&lt;/code&gt; in this case, is added and stored in &lt;code&gt;singleVal&lt;/code&gt;.&lt;/p&gt;




&lt;p&gt;So I decided to test the two algorithms and see which performed better. Here are the results from &lt;a href="https://jsbench.me/" rel="noopener noreferrer"&gt;https://jsbench.me/&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;As you can see the &lt;code&gt;for&lt;/code&gt;-loop outperformed the reduce method.&lt;/p&gt;

&lt;p&gt;The results from the tests showed me the performance benefits of using one over the other, however it did not explain the programmatic difference I was looking for. So I decided to keep looking…&lt;/p&gt;

&lt;p&gt;Eventually, I found the answer!&lt;/p&gt;

&lt;p&gt;Reduce in JavaScript is the alias for Fold, a higher order function that analyzes a recursive data structure and through use of a given combining operation, recombines the results of recursively processing its constituent parts, building up a return value. &lt;/p&gt;

&lt;p&gt;In simpler terms, the elements are combined in a way that reflects the combination with the next element, and so on until all elements are exhausted.&lt;/p&gt;

&lt;p&gt;Folds and maps are used to transform each value of a data structure independently, and filters are used to eliminate some elements from the data structure. Using &lt;code&gt;for&lt;/code&gt;-loops as a jack of all trades tends to obscure the actual operation the loop performs. So from a programming standpoint, reduce is more eloquent and clear in its purpose.&lt;/p&gt;

&lt;p&gt;In summary, we are able to determine the distinctions between the two approaches are contingent upon input and the design pattern of the programmer.&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>reduce</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What is expected from a Junior developer?</title>
      <dc:creator>Byte Sized</dc:creator>
      <pubDate>Tue, 28 Sep 2021 16:40:27 +0000</pubDate>
      <link>https://dev.to/nspired/what-is-expected-from-a-junior-developer-24ck</link>
      <guid>https://dev.to/nspired/what-is-expected-from-a-junior-developer-24ck</guid>
      <description>&lt;p&gt;Are you interviewing for web developer jobs and asking yourself, "What is expected from a junior developer?"&lt;/p&gt;

&lt;p&gt;Here's what happened in my first month as a Bootcamp graduate.&lt;/p&gt;




&lt;p&gt;No one expected me to code right away. Contrary to what you might think the company is not looking for you to contribute on your first day. Most companies will have an onboarding process so be sure to ask about it in your interview.&lt;/p&gt;




&lt;p&gt;My first tickets was not me building a highly visible feature. When I first started I mostly worked on documentation, setting up new projects, and bug tickets. The importance here is to use this time to be a sponge. There is no pressure on you and your team is there to help.&lt;/p&gt;




&lt;p&gt;I thought I was moving slowly when comparing myself to senior devs. It's easy to be discouraged when you are working with people who have been doing this for years. You want to show them you belong, I get it, trust me! Keep in mind you are new and in time you will get there.&lt;/p&gt;




&lt;p&gt;Here are some developer workflow hacks I used to increase my speed and productivity &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;VSCode Extensions &lt;a href="https://twitter.com/code"&gt;@code&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Customized my terminal with Zsh and aliases &lt;a href="https://twitter.com/ohmyzsh"&gt;@ohmyzsh&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Bash scripts&lt;/li&gt;
&lt;/ul&gt;




&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/saviomartin/34-ultimate-vs-code-extensions-to-increase-productivity-4hee"&gt;https://dev.to/saviomartin/34-ultimate-vs-code-extensions-to-increase-productivity-4hee&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://freecodecamp.org/news/how-to-configure-your-macos-terminal-with-zsh-like-a-pro-c0ab3f3c1156/"&gt;https://freecodecamp.org/news/how-to-configure-your-macos-terminal-with-zsh-like-a-pro-c0ab3f3c1156/&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Check out our tweet about Bash scripting 👉   &lt;a href="https://twitter.com/nspiredTech/status/1427652779645022213"&gt;https://twitter.com/nspiredTech/status/1427652779645022213&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;In short, regardless of the role, no one is expecting you to turn water into wine on your first day. So don't forget while you are interviewing ask clarifying questions about onboarding, mentorship, and what the expectation will be for you as a junior engineer. You got this!&lt;/p&gt;

</description>
      <category>100daysofcode</category>
      <category>career</category>
      <category>beginners</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Don't be an asshole. </title>
      <dc:creator>Byte Sized</dc:creator>
      <pubDate>Tue, 28 Sep 2021 16:31:09 +0000</pubDate>
      <link>https://dev.to/nspired/don-t-be-an-asshole-1h4k</link>
      <guid>https://dev.to/nspired/don-t-be-an-asshole-1h4k</guid>
      <description>&lt;p&gt;You can be a great developer and also be an asshole...&lt;/p&gt;

&lt;p&gt;Don't be an asshole. Here are 3 reasons why soft skills are so important. &lt;/p&gt;




&lt;p&gt;Your team will consist of designers, product managers, and your hot #React skills will not get you far with people who do not relate to your skills as a developer or understand the value these skills brings. &lt;/p&gt;

&lt;p&gt;Show your communication skills, team building, people will notice you and care about your contributions.&lt;/p&gt;




&lt;p&gt;Tech skills change and are replaceable. If you want to have a career in tech you need to bring more to the table! Are you supportive? Optimistic? Overall good person to be around and work with? These skills will serve you wherever you go and helps when it comes time for reviews.&lt;/p&gt;




&lt;p&gt;You’ll become a problem solver. Software engineers are problem solvers. Don't focus on just hard skills, consider adding more empathy to your work. Start developing with the customer in mind. Soft skills will help you connect with human needs and make you more well rounded.&lt;/p&gt;

&lt;p&gt;Empathy will get you far &lt;a href="https://www.forbes.com/sites/tracybrower/2021/09/19/empathy-is-the-most-important-leadership-skill-according-to-research/"&gt;as an employee and as a potential leader&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;Did you enjoy this blog post? Check us out on Twitter &lt;a href="https://twitter.com/@nspiredTech"&gt;@nspiredTech&lt;/a&gt; for more tech content!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>100daysofcode</category>
      <category>coding</category>
      <category>programming</category>
    </item>
    <item>
      <title>let and const vs var scoping</title>
      <dc:creator>Byte Sized</dc:creator>
      <pubDate>Mon, 27 Sep 2021 22:00:36 +0000</pubDate>
      <link>https://dev.to/nspired/let-and-const-vs-var-scoping-8ei</link>
      <guid>https://dev.to/nspired/let-and-const-vs-var-scoping-8ei</guid>
      <description>&lt;p&gt;Starting from ES6, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; handle scoping differently from &lt;code&gt;var&lt;/code&gt;. With &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; being available since ES6, you have no excuse to use &lt;code&gt;var&lt;/code&gt; anymore!&lt;/p&gt;

&lt;p&gt;You might have seen people mention that &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; are "lexically scoped", but what does that really mean?&lt;/p&gt;

&lt;p&gt;In simple terms, it just means that the structure of your program itself shows where a scope begins and where it ends: opening a curly brace for a function creates a new scope, closing it ends the scope.&lt;/p&gt;

&lt;p&gt;Here's an annotated code example that shows the differences between the two&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;function&lt;/span&gt; &lt;span class="nx"&gt;foobar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// Start of a scope&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;x&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="c1"&gt;// Variables declared with `var` are "hoisted"&lt;/span&gt;
    &lt;span class="c1"&gt;// and initialized to `undefined`.&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// undefined&lt;/span&gt;
    &lt;span class="c1"&gt;// `let` and `const` are hoisted too, but not &lt;/span&gt;
    &lt;span class="c1"&gt;// initialized to `undefined`.&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Uncaught ReferenceError: bar is not defined&lt;/span&gt;

    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="dl"&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;bar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bar&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="c1"&gt;// `foo` is scoped to the function , so it's &lt;/span&gt;
  &lt;span class="c1"&gt;// available anywhere in the function block&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "foo"&lt;/span&gt;
  &lt;span class="c1"&gt;// `bar` is scoped to a block, here `if (x == 1) {}`,&lt;/span&gt;
  &lt;span class="c1"&gt;// so when the block ends (after the `}`), `bar`&lt;/span&gt;
  &lt;span class="c1"&gt;// isn't available anymore.&lt;/span&gt;
  &lt;span class="c1"&gt;// Any pair of curly braces `{}` creates a new block.&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Uncaught ReferenceError: bar is not defined&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Did you enjoy this blog post? Check us out on Twitter &lt;a href="https://twitter.com/@nspiredTech"&gt;@nspiredTech&lt;/a&gt; for more tech content!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Top 5 command line tools you should try</title>
      <dc:creator>Byte Sized</dc:creator>
      <pubDate>Mon, 27 Sep 2021 16:08:07 +0000</pubDate>
      <link>https://dev.to/nspired/top-5-command-line-tools-you-should-try-1c95</link>
      <guid>https://dev.to/nspired/top-5-command-line-tools-you-should-try-1c95</guid>
      <description>&lt;h2&gt;
  
  
  &lt;code&gt;ripgrep&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;You've probably used grep before. &lt;code&gt;ripgrep&lt;/code&gt; is like &lt;code&gt;grep&lt;/code&gt;, just better. Faster, with nicer defaults, and more powerful! &lt;a href="https://github.com/BurntSushi/ripgrep"&gt;https://github.com/BurntSushi/ripgrep&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;fzf&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;I probably use &lt;code&gt;fzf&lt;/code&gt; more than any other tool in this list. If you have a hard time remembering where you put this very important module in your codebase, just type &lt;code&gt;fzf&lt;/code&gt; and it'll bring up a list of files that you can easily sift through &lt;a href="https://github.com/junegunn/fzf"&gt;https://github.com/junegunn/fzf&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;jq&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;If you're working with JSON, you need to try &lt;code&gt;jq&lt;/code&gt;. It allows you to parse, filter and transform any JSON file with an a simple query language. &lt;a href="https://github.com/stedolan/jq"&gt;https://github.com/stedolan/jq&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;less +F&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;You might have used less before. But did you know you could use it like &lt;code&gt;tail --follow&lt;/code&gt;? &lt;code&gt;less +F logfile&lt;/code&gt; will stream any new lines added to your log file! You can also filter the stream with &amp;amp; or pause it with &lt;code&gt;Ctrl+C&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;entr&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;If you're tired of having to run your test suite manually any time you update a file, try this: &lt;code&gt;git ls-files | entr -c &amp;lt;command to run your tests&amp;gt;&lt;/code&gt;. It will run your command every time you update a file in your project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/eradman/entr"&gt;https://github.com/eradman/entr&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Thanks for reading this far! Do you have any other cool command line tools that you think should have made this list?&lt;/p&gt;

&lt;p&gt;For more tech content like this, follow us &lt;a href="https://twitter.com/nspiredTech"&gt;@nspiredTech&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Visit &lt;a href="https://nspired.tech"&gt;https://nspired.tech&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>bash</category>
      <category>linux</category>
    </item>
    <item>
      <title>The secret of big O notation</title>
      <dc:creator>Byte Sized</dc:creator>
      <pubDate>Mon, 27 Sep 2021 16:06:45 +0000</pubDate>
      <link>https://dev.to/nspired/the-secret-of-big-o-notation-4apg</link>
      <guid>https://dev.to/nspired/the-secret-of-big-o-notation-4apg</guid>
      <description>&lt;p&gt;&lt;strong&gt;⚡ TL;DR:&lt;/strong&gt; Big O notation helps us describe the efficiency of algorithms. It will help you make a more informed decision as to which algorithm is right for your specific use case. In addition, you'll likely be expected to know this in any technical interview.&lt;/p&gt;




&lt;h3&gt;
  
  
  Which one do you choose? 🤔
&lt;/h3&gt;

&lt;p&gt;Imagine you're getting ready to download Animal Crossing to play with a group of friends. You don't think twice about it, you click "Install" and a few minutes later it's ready to play. &lt;br&gt;
But now, you hear Drake is having a concert on Fortnite on Saturday. You're super excited, he just dropped his new album. You &lt;em&gt;have&lt;/em&gt; to see that! Now think about this. Fortnite is about 20GB. &lt;br&gt;
Assuming you have a somewhat decent internet connection, it could still take up to 3 days to download it! Amazon offers next day delivery for the physical copy of Fortnite #AmazonPrime. &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%2Fi.giphy.com%2Fmedia%2Fl2QDSKSkhqITBLYBy%2Fgiphy.webp" 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%2Fi.giphy.com%2Fmedia%2Fl2QDSKSkhqITBLYBy%2Fgiphy.webp" alt="Next-day delivery"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see how in some cases it might be faster to get a game from Amazon, and in some cases it's just faster to download it. But regardless of the game's size, getting it from Amazon with next-day delivery is always going to take the same amount of time. Downloading a game on the other hand, varies based on its size.&lt;/p&gt;

&lt;p&gt;In this case, Amazon takes &lt;code&gt;O(1)&lt;/code&gt; time to get a game (it's constant!), and downloading it is &lt;code&gt;O(n)&lt;/code&gt;, &lt;code&gt;n&lt;/code&gt; being the size of the game: the bigger the game, the longer it will take.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;O(1)&lt;/code&gt;, &lt;code&gt;O(n)&lt;/code&gt;, what does that even mean? 🤷‍♀️
&lt;/h3&gt;

&lt;p&gt;The big O notation is used to classify time and space requirements of your algorithms. &lt;/p&gt;

&lt;p&gt;Here are some rules to remember when trying to find the complexity of an algorithm:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Always drop constant terms.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;twoLoops&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="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;n&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="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;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// First loop, O(n)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&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="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;j&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Second loop, also O(n)&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;Here, our &lt;code&gt;twoLoops&lt;/code&gt; function iterates &lt;code&gt;n&lt;/code&gt; times twice. What do you think the big O notation for this function should be?&lt;/p&gt;

&lt;p&gt;Intuitively, we could start by saying that it is &lt;code&gt;O(2n)&lt;/code&gt;: the first loop is &lt;code&gt;O(n)&lt;/code&gt; and the second loop is also &lt;code&gt;O(n)&lt;/code&gt;, adding them up we get &lt;code&gt;2 ✕ O(n)&lt;/code&gt; or &lt;code&gt;O(2n)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;With out first rules, we know that constant terms (here, &lt;code&gt;2&lt;/code&gt;) must disappear. So our big O complexity is actually &lt;code&gt;O(n)&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Always drop non-dominant terms.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;nestedLoops&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="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;n&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="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;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// First loop, O(n)&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;x&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;x&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="nx"&gt;x&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;y&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;y&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="nx"&gt;y&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="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;j&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Nested loop, O(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;In this example we still have the first loop but we also have a nested loop. Adding those two big O together, we would get &lt;code&gt;O(n + n²)&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;This rule tells us that since &lt;code&gt;n²&lt;/code&gt; "dominates" (it's the biggest term), we need to remove any other term. We end up with &lt;code&gt;O(n²)&lt;/code&gt;, exponential growth.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;💡 Did you know?&lt;/em&gt; Big O has a few siblings, including the &lt;a href="https://en.wikipedia.org/wiki/Big_O_notation#Related_asymptotic_notations" rel="noopener noreferrer"&gt;little o and big Omega notations&lt;/a&gt;, which are other examples of asymptotic notations. However, in the case of technical interviews, big O is the most useful.&lt;/p&gt;

&lt;h3&gt;
  
  
  Space AND Time complexity
&lt;/h3&gt;

&lt;p&gt;In an interview setting, you'll likely be asked to talk about the big O complexity of the solution you provided to a problem. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Space complexity measures the space growth of your algorithm. It helps you answer the question "How much space will my algorithm require relative to the size of the input?". &lt;/li&gt;
&lt;li&gt;Time complexity measures the runtime growth of your algorithm. It helps you answer the question "How much time will my algorithm run relative to the size of the input?".
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;badFibonacci&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&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="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;2&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;n&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="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;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;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;arr length:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;arr&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&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="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;badFibonacci&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;badFibonacci&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="mi"&gt;21&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How could we go about calculating the big O complexity here?&lt;/p&gt;

&lt;p&gt;For space complexity, we need to look at the variables we're using: &lt;code&gt;arr&lt;/code&gt; and &lt;code&gt;i&lt;/code&gt;. &lt;code&gt;i&lt;/code&gt; doesn't change in size, it's constant. Knowing our rule about constants, we can ignore it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;arr&lt;/code&gt; however, is different: its size is going to grow relative to &lt;code&gt;n&lt;/code&gt;. The bigger the &lt;code&gt;n&lt;/code&gt;, the larger the array: this is linear growth, &lt;code&gt;O(n)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To calculate the time complexity, we look at the number of steps taken to reach the solution. In this case, there is a single loop that grows relative to &lt;code&gt;n&lt;/code&gt;, which means our big O complexity is also &lt;code&gt;O(n)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.giphy.com%2Fmedia%2F5z0cCCGooBQUtejM4v%2Fgiphy.webp" 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%2Fi.giphy.com%2Fmedia%2F5z0cCCGooBQUtejM4v%2Fgiphy.webp" alt="Problem solved"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;When you see this, you might not necessarily think that anything is wrong with this solution. After all, it does what you want it to do.&lt;/p&gt;

&lt;p&gt;But in an interview setting, you always have to ask yourself: &lt;em&gt;can this solution be better?&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;🚨 Your first solution is often a &lt;em&gt;Brute Force&lt;/em&gt; approach. You just want to get the code working. Once you have identified a solution, you'll want to &lt;em&gt;optimize&lt;/em&gt; it, improving its runtime and space requirements. &lt;br&gt;
Depending on the problem at hand, you'll know what type of solution you need to provide.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tradeoffs
&lt;/h3&gt;

&lt;p&gt;In most cases, when optimizing a solution, you are going to make tradeoffs: give up speed, to lessen space requirements, or give up space, to improve speed.&lt;/p&gt;

&lt;p&gt;🚨 This is an important talking point during your interview to be able to explain your optimization choices in terms of tradeoffs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Best or worst case scenario?
&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;function&lt;/span&gt; &lt;span class="nf"&gt;badFindIndex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;needle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;haystack&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;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;haystack&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;needle&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;haystack&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="k"&gt;return&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="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&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="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;badFindIndex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;b&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;c&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;badFindIndex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;z&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;b&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;c&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="kc"&gt;null&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the best case scenario is when &lt;code&gt;needle&lt;/code&gt; is the first element of &lt;code&gt;haystack&lt;/code&gt;: we don't have to traverse the rest of the array in order to find the target.&lt;/p&gt;

&lt;p&gt;For the worst case scenario, &lt;code&gt;needle&lt;/code&gt; is not in the &lt;code&gt;haystack&lt;/code&gt;. However, we have to traverse the entire array just to confirm it's not present.&lt;/p&gt;

&lt;p&gt;🚨 The array is really small here, but in an interview setting, you have to think big! Google has databases with billions of records -- try to think of these kind of scenarios when optimizing your solution.&lt;/p&gt;

&lt;p&gt;When calculating big O, &lt;em&gt;always&lt;/em&gt; think of the worst case scenario!&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;To wrap things up, the secret to big O notation is knowing how to choose the right algorithm while considering factors such as space and time complexity, tradeoffs and best and worst case scenarios. &lt;/p&gt;

&lt;p&gt;Hopefully, you now feel prepared for your next technical interview! &lt;/p&gt;




&lt;p&gt;What did you think of the post? Did you learn anything new? We would love to hear from you!&lt;/p&gt;

&lt;p&gt;If you are still looking for more practice, be on the lookout for our next post. We will solve &lt;a href="https://leetcode.com/problems/valid-parentheses/" rel="noopener noreferrer"&gt;a popular interview coding problem from leetcode&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Also there is &lt;a href="https://leetcode.com/problems/valid-parentheses/" rel="noopener noreferrer"&gt;a free computer science course on EdX&lt;/a&gt; taught by Hardvard professors where you will learn fundamental principles. It's a great resume builder and you get a certificate at the end of the course! &lt;/p&gt;




&lt;p&gt;As an added bonus, here's a big O cheatsheet we made! 🔥&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632000025302%2F-sa8Yu0tn.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632000025302%2F-sa8Yu0tn.png" alt="big-o.png"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>career</category>
      <category>codenewbie</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Linked list coding challenge</title>
      <dc:creator>Byte Sized</dc:creator>
      <pubDate>Mon, 27 Sep 2021 16:00:12 +0000</pubDate>
      <link>https://dev.to/nspired/linked-list-coding-challenge-cm0</link>
      <guid>https://dev.to/nspired/linked-list-coding-challenge-cm0</guid>
      <description>&lt;p&gt;Today, we’ll be solving a &lt;a href="https://www.freecodecamp.org/"&gt;freecodecamp&lt;/a&gt; algorithm question: &lt;a href="https://www.freecodecamp.org/learn/coding-interview-prep/data-structures/remove-elements-from-a-linked-list-by-index"&gt;https://www.freecodecamp.org/learn/coding-interview-prep/data-structures/remove-elements-from-a-linked-list-by-index&lt;/a&gt;, removing an element from a linked list by index. Try to contain your excitement! 😂&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dsUPrZ03--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631550964910/YNAJOC4Pr.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dsUPrZ03--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631550964910/YNAJOC4Pr.gif" alt="excited.gif"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;We recommend reading &lt;a href="https://bytesized.news/issue-1-arrays-and-lists"&gt;Arrays and Lists 📚&lt;/a&gt; before starting the coding exercise. This will ensure you have a firm understanding of the data structures used in the following exercise.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;⚡ TL;DR:&lt;/strong&gt; In linked list, elements are removed by linking the previous element with the next element, thus removing any link to the element to be removed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setup
&lt;/h3&gt;

&lt;p&gt;Before we get started, let’s picture yourself waiting in line at the grocery store. The line you’re waiting in will be our linked list.&lt;/p&gt;

&lt;p&gt;Each person can only see the person in front of them, but they can’t see who is behind them. Bummer! 😞&lt;/p&gt;

&lt;p&gt;Now that we have an idea of what a linked list looks like, let’s set it up. We’ll do this in JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u8pMmg2D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551013035/Vhz-jXTJf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u8pMmg2D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551013035/Vhz-jXTJf.png" alt="carbon_2830_29.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;LinkedList&lt;/code&gt; has a &lt;code&gt;head&lt;/code&gt;, this is the first &lt;code&gt;Node&lt;/code&gt; of the list. Think of it as the last person standing in the line, they can see someone in front of them, but no one is standing behind them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--67VjGbsD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551070638/LOJP_qnP6.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--67VjGbsD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551070638/LOJP_qnP6.gif" alt="line.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each &lt;code&gt;Node&lt;/code&gt; contains a value and a link to the next &lt;code&gt;Node&lt;/code&gt; in the list.&lt;/p&gt;

&lt;p&gt;Now, let’s create a list:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NOK4-WFd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551120942/pi34w6nIm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NOK4-WFd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551120942/pi34w6nIm.png" alt="carbon_2847_29.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, our &lt;code&gt;head&lt;/code&gt;‘s value is &lt;code&gt;0&lt;/code&gt;. The rest of the elements are called the &lt;code&gt;tail&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pTP_sy2x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551164235/ZLVDBtbic.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pTP_sy2x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551164235/ZLVDBtbic.png" alt="carbon_2841_29.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Walking the list 🚶‍♀️
&lt;/h3&gt;

&lt;p&gt;In this step we’re going to traverse the list, node by node. As we can see, we’re starting with a list of five elements. For now, we just want to look at &lt;em&gt;every&lt;/em&gt; element of the list.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CABJHS76--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551328376/6YQvmt_xl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CABJHS76--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551328376/6YQvmt_xl.png" alt="carbon_2832_29.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s important to remember that the last node in the list will be pointing to &lt;code&gt;null&lt;/code&gt; (this is the person at the front of the line). Once we reach this node, &lt;code&gt;node = node.next&lt;/code&gt; will set &lt;code&gt;node&lt;/code&gt; to &lt;code&gt;null&lt;/code&gt; and we will stop the iteration.&lt;/p&gt;

&lt;p&gt;This is like asking to the last person waiting in line who’s in front of them, then asking the same thing to that person, until you reach the person at the front of the line.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4RXX6NVy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551395149/DgukNjaj-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4RXX6NVy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551395149/DgukNjaj-.png" alt="carbon_2842_29.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Finding a node
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WkM9rWC5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551451422/ymPI9uU-u.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WkM9rWC5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551451422/ymPI9uU-u.gif" alt="books.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we know how to traverse the entire list, we want to find the one we’re looking for. For that we’re going to need a counter, to keep track of the number of nodes we’ve seen so far when walking the list.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9kYFDqRN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551474000/K8H3B3TyL.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9kYFDqRN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551474000/K8H3B3TyL.png" alt="carbon_2833_29.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With the &lt;code&gt;counter&lt;/code&gt; going up with every node, we can now compare it to the given &lt;code&gt;index&lt;/code&gt;. When our &lt;code&gt;counter&lt;/code&gt; is equal to &lt;code&gt;index&lt;/code&gt;, we know we’ve reached the node we want to remove:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X_M5n6K9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551533152/xHbDLpREN.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X_M5n6K9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551533152/xHbDLpREN.png" alt="carbon_2834_29.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Removing the node
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--l2gDkrz0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551569636/du16f1cNI.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l2gDkrz0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551569636/du16f1cNI.gif" alt="wheres-my-book-cannot-find-it-still.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Having done the heavy lifting in the previous steps, removing the node has become a lot easier!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6EGbk1lf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551588114/LjVpw0EP9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6EGbk1lf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551588114/LjVpw0EP9.png" alt="carbon_2837_29.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s go through the steps, one more time:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We initialize a few variables:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;node&lt;/code&gt;, that we set to the &lt;code&gt;head&lt;/code&gt; (first element) of our linked list,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;counter&lt;/code&gt;, which we’ll use to track the index of the node we’re looking at in the &lt;code&gt;while&lt;/code&gt; loop,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;prev&lt;/code&gt;, which we’ll set to the previous element we looked at in the &lt;code&gt;while&lt;/code&gt; loop.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;We start our loop, with a condition that says “don’t stop unless &lt;code&gt;node&lt;/code&gt; is &lt;code&gt;null&lt;/code&gt;”&lt;/li&gt;
&lt;li&gt;We compare our &lt;code&gt;counter&lt;/code&gt; to the &lt;code&gt;index&lt;/code&gt; we want to remove.

&lt;ul&gt;
&lt;li&gt;If they’re equal, it’s time to remove the &lt;code&gt;node&lt;/code&gt;! We make the previous node &lt;code&gt;prev&lt;/code&gt; point to the next node in the list, &lt;code&gt;node.next&lt;/code&gt; – now, no node in the list points to the one we want to remove anymore!&lt;/li&gt;
&lt;li&gt;If not, we just keep going, updating &lt;code&gt;prev&lt;/code&gt; to be the current &lt;code&gt;node&lt;/code&gt;, and &lt;code&gt;node&lt;/code&gt; to be the next one. We also increment our &lt;code&gt;counter&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Think of it this way: with our group waiting in line, if someone in the middle of the line leaves, then the person behind them can now see the next person in front of them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5-F--Hf7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551753747/FwA-k4wY_.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5-F--Hf7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551753747/FwA-k4wY_.png" alt="carbon_2845_29.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Handling the edge cases
&lt;/h3&gt;

&lt;p&gt;Now you might be wondering, what happens if the index is 0? Less than 0? What if it’s bigger than the length of our list? And you’re right, these are edge cases we will have to handle! Let’s see how we can do that:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mW2koiUl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551792316/FCuCpGx0s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mW2koiUl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551792316/FCuCpGx0s.png" alt="carbon_2836_29.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a bonus, here’s &lt;a href="https://leetcode.com/problems/reverse-linked-list/"&gt;this question from leetcode&lt;/a&gt;. We’ll solve it, but with a twist. 🤔 Can you spot the error?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4evC4JHH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551843608/0LimmJyEa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4evC4JHH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631551843608/0LimmJyEa.png" alt="carbon_2846_29.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hint:&lt;/em&gt; do you have a way of finding where the list starts?&lt;/p&gt;

&lt;h4&gt;
  
  
  Before you go…
&lt;/h4&gt;

&lt;p&gt;Thanks for reading! If you enjoyed this article, please give it a like 👍 to help others find it. And do not hesitate to share your thoughts in the comments below.&lt;/p&gt;

&lt;h2&gt;
  
  
  💡 Tip of the week
&lt;/h2&gt;

&lt;p&gt;Are you learning git commands? Here is a resource you can use so you don’t have to remember it all: &lt;a href="https://ohshitgit.com/"&gt;https://ohshitgit.com/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🔗 What else is going on in tech?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Are you ready for &lt;a href="https://www.theverge.com/22588022/mark-zuckerberg-facebook-ceo-metaverse-interview"&gt;Facebook’s Metaverse&lt;/a&gt;?&lt;/li&gt;
&lt;li&gt;The first release candidate for &lt;a href="https://docs.python.org/3.10/whatsnew/3.10.html"&gt;Python 3.10&lt;/a&gt; is out!&lt;/li&gt;
&lt;li&gt;Looking for a tech podcast recommendation? Check out the &lt;a href="https://devchat.tv/podcasts/elixir-mix/"&gt;Elixir Mix&lt;/a&gt;!&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>algorithms</category>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Arrays and Lists 📚</title>
      <dc:creator>Byte Sized</dc:creator>
      <pubDate>Mon, 27 Sep 2021 15:58:38 +0000</pubDate>
      <link>https://dev.to/nspired/arrays-and-lists-1gc7</link>
      <guid>https://dev.to/nspired/arrays-and-lists-1gc7</guid>
      <description>&lt;p&gt;&lt;strong&gt;⚡ TL;DR:&lt;/strong&gt; Arrays are fast and compact. Linked lists are not as compact, but adding or removing elements from them can be more efficient!&lt;/p&gt;




&lt;p&gt;You probably already know how to use arrays and are familiar with methods like &lt;code&gt;push&lt;/code&gt;, &lt;code&gt;pop&lt;/code&gt;, etc. The purpose of this issue is to give you an understanding of arrays as a data structure and how they differ from lists.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;**Why would you care?&lt;/em&gt;* For those who are preparing for a technical interview or would like to deepen your knowledge of computer science, this is the article for you.*&lt;/p&gt;

&lt;p&gt;Arrays and lists are easy to mix up, so let’s try to make sense of what the differences are and how they work! ⚙️&lt;/p&gt;

&lt;p&gt;You can think of memory as a bookshelf:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CBhiSFil--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631549902604/Nl9Hq-ENm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CBhiSFil--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631549902604/Nl9Hq-ENm.png" alt="bookshelf.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now imagine you got the first four volumes of Game of Thrones 🐉:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4T50PRrc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631548903531/mNLdaL4El.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4T50PRrc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631548903531/mNLdaL4El.png" alt="4-volumes.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is your array. Now you wouldn’t want to store these volumes separately: if you find volume 1 you want to be able to find volume 2 easily. So you’ll find a place were you can put the four of them together. Luckily, our top shelf has room for &lt;em&gt;exactly&lt;/em&gt; four volumes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H2r6slcd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631549352361/aIc3dH3wT.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H2r6slcd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631549352361/aIc3dH3wT.png" alt="bookshelf-with-4-volumes.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You found a spot for these, great. But, surprise! A friend comes over and gives you volume 5 📕&lt;/p&gt;

&lt;p&gt;You run to your bookshelf, only to realize, you don’t have any room left next to volume 4 🙁&lt;/p&gt;

&lt;p&gt;Reorganizing the bookshelf to make more room near volume 4 would work, but that seems like a lot of effort…&lt;/p&gt;

&lt;p&gt;Instead, we’re going to move the first four volumes to a larger empty space. Now we can add the fifth volume!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wlpwH4_7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631549385659/6uZBHOc4a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wlpwH4_7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631549385659/6uZBHOc4a.png" alt="volume-5-fits.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Phew, that wasn’t easy! 🥵 These volumes are heavy, and you don’t want to go through the hassle of moving all of them every time you don’t have enough room for a new one.&lt;/p&gt;

&lt;p&gt;So what are your options here? Well, we tried to do it the &lt;em&gt;array&lt;/em&gt; way: put each volume next to each other, and move the entire series when you don’t have enough room for another volume. What if we tried to do it the &lt;em&gt;list&lt;/em&gt;¹ way instead?&lt;/p&gt;

&lt;p&gt;We’ll need a little bit of setup before getting into this. We are going to assign a letter to each shelf, and a number to each column of book:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kOSGoMNL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631549407512/IGng7n0NQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kOSGoMNL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631549407512/IGng7n0NQ.png" alt="bookshelf-with-coordinates.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, each location on our bookshelf has a set of coordinates. For example, the third book of the top shelf is at position &lt;code&gt;A2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Instead of storing our volumes next to each other, we are going to put the first volume anywhere in the bookshelf:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TRnbRAEi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631549432886/7_Q4QgmCh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TRnbRAEi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631549432886/7_Q4QgmCh.png" alt="bookshelf-volume-1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And now, we’re going to do the same with the second volume. Once we’ve found a location for it, we’re going to add a note next to the first volume with the coordinates of the second volume:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZFstLTZz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631549464315/Tg3H6aVhK.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZFstLTZz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631549464315/Tg3H6aVhK.png" alt="bookshelf-volumes-1-2.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can do this until we reach the fourth volume, where the note will be empty since we don’t have our fifth volume yet:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KdKnyYAu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631549520108/DumU3r0CB.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KdKnyYAu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1631549520108/DumU3r0CB.png" alt="bookshelf-4-linked-books.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We just made a &lt;em&gt;singly linked list&lt;/em&gt;: we have a single note next to each book that tells us where to find the next one.&lt;/p&gt;

&lt;p&gt;Now you might be thinking, this is great, but why do I have to waste so much space storing those notes?&lt;/p&gt;

&lt;p&gt;And you would be right: linked lists take up more space than arrays²! You give up some space, but you don’t have to worry about moving things around to add a volume to your series. As long as you have space for a book and a note, everything’s fine! Removing a volume in the middle is also a lot simpler: if you want to remove volume 2, just change the note after volume 1 with the coordinates of volume 3.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaway&lt;/strong&gt;: trade-offs. When discussing the differences between &lt;em&gt;arrays&lt;/em&gt; and &lt;em&gt;lists&lt;/em&gt;, it is important to understand when and why to use one or the other — knowing this will make you stand out during any technical interview! ✨&lt;/p&gt;

&lt;p&gt;&lt;em&gt;[1]: Usually, people use **list&lt;/em&gt;* to mean &lt;strong&gt;linked list&lt;/strong&gt;, and more specifically &lt;strong&gt;singly linked lists&lt;/strong&gt;. There are other types of lists, but &lt;strong&gt;singly linked lists&lt;/strong&gt; are the most common type.*&lt;/p&gt;

&lt;p&gt;&lt;em&gt;[2]: Technically this might not always be true, because of the way programming languages handles memory allocation for arrays. You can read more about this &lt;a href="https://en.wikipedia.org/wiki/Dynamic_array#Growth_factor"&gt;here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  💡 Tip of the week
&lt;/h2&gt;

&lt;p&gt;You can use &lt;code&gt;git switch -&lt;/code&gt; to switch back to your previous branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;main&lt;span class="o"&gt;)&lt;/span&gt; git switch other-branch
&lt;span class="o"&gt;(&lt;/span&gt;other-branch&lt;span class="o"&gt;)&lt;/span&gt; git switch -
&lt;span class="o"&gt;(&lt;/span&gt;main&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://git-scm.com/docs/git-switch"&gt;Learn more&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🔗 What else is going on in tech?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If you are starting to learn about flexbox in CSS, this might be for you: &lt;a href="https://knightsoftheflexboxtable.com/"&gt;https://knightsoftheflexboxtable.com/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For all the Rubyist around here, Stripe had some exciting news! &lt;a href="https://sorbet.org/blog/2021/07/30/open-sourcing-sorbet-compiler"&gt;https://sorbet.org/blog/2021/07/30/open-sourcing-sorbet-compiler&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A beautiful and free library of UI components for Tailwind: &lt;a href="https://daisyui.com/"&gt;https://daisyui.com/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, if GitHub is your daily driver, checkout this new awesome feature! &lt;a href="https://twitter.com/DynamicWebPaige/status/1425502379777019909"&gt;https://twitter.com/DynamicWebPaige/status/1425502379777019909&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;PS: We would love to know how you felt about this article, did you find it helpful, and are there topics you’d love to see covered? Tag @nspiredTech on Twitter if there’s anything you want to share :-)&lt;/em&gt;&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
