<?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: Miguel Ben</title>
    <description>The latest articles on DEV Community by Miguel Ben (@migben).</description>
    <link>https://dev.to/migben</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%2F89047%2F3d2c6adb-e50e-4749-92e7-99e73a384013.png</url>
      <title>DEV Community: Miguel Ben</title>
      <link>https://dev.to/migben</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/migben"/>
    <language>en</language>
    <item>
      <title>Intro to Data Structures + Algo [Part 3]</title>
      <dc:creator>Miguel Ben</dc:creator>
      <pubDate>Mon, 17 Aug 2020 03:56:59 +0000</pubDate>
      <link>https://dev.to/migben/intro-to-data-structures-algo-part-3-test-14im</link>
      <guid>https://dev.to/migben/intro-to-data-structures-algo-part-3-test-14im</guid>
      <description>&lt;p&gt;Hello everyone, it's been another week and is time for the next part of our series. Today we are going to be talking about Linked list. We are covering two type of linked list, singly and doubly. So what problems did we had with static arrays? &lt;/p&gt;

&lt;p&gt;We were able to allocate a certain amount of data or memory next to each other but then both dynamic and static arrays can increase their memory once they hit a certain limit and double the memory in another location. However, this operation of doubling up memory has a performance implication and it cost &lt;strong&gt;O(n)&lt;/strong&gt;. Additionally, arrays have bad performance for operations such as delete and / or insertion that have to shift indexes over. Specially when you do these operations when is not at the end of the array.&lt;/p&gt;

&lt;p&gt;Then, as to our rescue came the hash tables which allows for you to store whatever you want in memory. Hash tables will know where to store it for us and take care of it. Unfortunately, hash tables by default aren't ordered but don't sweat it that where Linked list will make our life easier. Does this mean that Link lists are the go to alternative now? No, there is never an absolute answer in data structures. Remember, there will always be some trade offs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Hashes will be covered in a future post. 🙇&lt;/p&gt;

&lt;p&gt;A singly linked list contains a set of nodes. These nodes contains two elements, the value of the data that you want to store and a pointer to the next node in line. The first node is called the 'Head' and the last one is 'Tail' the after the last node it points to 'Null'.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dOT6tZ3L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://media.geeksforgeeks.org/wp-content/cdn-uploads/gq/2013/03/Linkedlist.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dOT6tZ3L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://media.geeksforgeeks.org/wp-content/cdn-uploads/gq/2013/03/Linkedlist.png" alt="example1"&gt;&lt;/a&gt;&lt;/p&gt;
  a linked list consists of nodes where each node contains a data field and a reference link to the next node in the list.



&lt;h3&gt;
  
  
  &lt;strong&gt;Example 1&lt;/strong&gt; - Pseudo Code
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* 
head
eggs 
4   --&amp;gt; ham     tail
        6  --&amp;gt; cheese
               12    --&amp;gt; null
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For more visual representation of algorithms use &lt;a href="https://visualgo.net/en"&gt;this&lt;/a&gt; website.&lt;/p&gt;

&lt;p&gt;Are linked list good or bad? First, on arrays you are able to start from whatever index of your choosing but on linked list you can only iterate from the head until you hit null.&lt;/p&gt;

&lt;p&gt;Let's talk about what do we mean about a pointer? refers to the next place (object or node) in memory. Simplest example for pointers in javascript is the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;objectOne&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;stock1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.33&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;objectTwo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;objectOne&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now let's jump to a more concrete example. This upcoming piece of code will be the base for our first exercise. The challenge is to complete this linked list. &lt;strong&gt;Tip:&lt;/strong&gt; Try completing an append() method that allows you to add the value to the list.&lt;a href="https://repl.it/join/fnmljwgs-mius00"&gt;&lt;strong&gt;SOLUTION&lt;/strong&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// 23 --&amp;gt; 51 --&amp;gt; 12&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;LinkedList&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;head&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;next&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;head&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// complete it for the linkedList pt 2&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myLinkedList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;LinkedList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;myLinkedList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;51&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;myLinkedList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now let's try creating a prepend() method for our list under the append method. Check out the Linkedlist2 script for the &lt;a href="https://repl.it/join/fnmljwgs-mius00"&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/WNs0uptipSG40/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/WNs0uptipSG40/giphy.gif" alt="tacoAll"&gt;&lt;/a&gt;&lt;/p&gt;
Until next time everyone eat your tacos!



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

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://visualgo.net/en"&gt;VisualAlgo.net&lt;/a&gt; by Dr Steven Halim&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.geeksforgeeks.org/data-structures/linked-list/"&gt;GeekforGeeks&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Hey y'all, thanks for sticking around in this mini series. We have covered the basics about linked list and Hopefully we have all learned a thing or two from today examples. If you guys have any suggestions or better examples please share them in the comment section below. P.S: I'm going to start updating all blogs now. Apologies for any inconvenience.&lt;/p&gt;

</description>
      <category>challenge</category>
      <category>beginners</category>
      <category>javascript</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Intro to Data Structures + Algo [Part 2]</title>
      <dc:creator>Miguel Ben</dc:creator>
      <pubDate>Mon, 10 Aug 2020 03:38:09 +0000</pubDate>
      <link>https://dev.to/migben/intro-to-data-structures-algo-part-2-6o3</link>
      <guid>https://dev.to/migben/intro-to-data-structures-algo-part-2-6o3</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;Intro&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Hey guys, it's another week for our coding challenges (Data Structures and Algorithms). Today we are going to be talking about Arrays which is one of the fundamentals Data Structures. However, in layman terms what is a data structure? It simply is things that we could built from scratch, for example an array. This is one of the most common topics in interviews, and you will usually see questions such as filter X elements from the array, reverse that other array or even start sorting this array.&lt;/p&gt;

&lt;p&gt;The best way for you to solve an array based question is to simply be more knowledgeable about this topic. Moreover, knowing more about fundamentals such as operators, loops and recursion will help. Another key benefit is that it offers fast O(1) search if you know the index, but adding and removing an element from an array is slow because you cannot change the size of the array once it's created.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/QqdyVT8H6uJ32/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/QqdyVT8H6uJ32/giphy.gif" alt="hohoo"&gt;&lt;/a&gt;&lt;/p&gt;
Hopefully, I do have your attention





&lt;h3&gt;
  
  
  &lt;strong&gt;Examples&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Before I forget, the following array methods have specific time complexities that you should keep in mind. The push() is a constant O(1), lookup() is O(1), insert() is O(n) &amp;amp; delete() O(n).&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;ratings&lt;/span&gt; &lt;span class="o"&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;M&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;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;X&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;F&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="c1"&gt;//                0    1    2    3  &lt;/span&gt;

&lt;span class="nx"&gt;ratings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;N&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// O(1)&lt;/span&gt;

&lt;span class="nx"&gt;ratings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;unshift&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;T&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// O(n)&lt;/span&gt;

&lt;span class="nx"&gt;ratings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;potatoes&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// O(n/2) simplified to O(n)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Great, now let's go over what are static and dynamic arrays. First, static arrays are the ones fixed in size, this means you are to specify ahead of time the number of elements your array will hold (Seen this more on C++ and Java). A Dynamic array allows us to copy and rebuild the array at a new memory location. What you need to remember is that Dynamic arrays expands as you add more elements, so you don't need to determine the size ahead of time.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: You should treat string questions as an array question.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/lkdH8FmImcGoylv3t3/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/lkdH8FmImcGoylv3t3/giphy.gif" alt="wait..what!"&gt;&lt;/a&gt;&lt;/p&gt;
Strings are simply an array of characters.






&lt;p&gt;A few array coding questions to practice with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;[EASY]&lt;/strong&gt; Create a function that reverses a string. &lt;a href="https://repl.it/join/pdnigahy-mius00"&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="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;reverse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;str&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;// leaving this here to get you started&lt;/span&gt;

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

&lt;span class="nx"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Pikachu loves his trainer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// reniart sih sevol uhcakiP&lt;/span&gt;

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


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;[EASY-MED]&lt;/strong&gt; Given two arrays that are sorted can you merge them into one big array (still sorted). &lt;a href="https://repl.it/join/pdnigahy-mius00"&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="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;mergeSortedArrs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;arr2&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="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;mergeSortedArrs&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;53&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;37&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="c1"&gt;// output =&amp;gt; [1,4,7,12,22,28,37,53]&lt;/span&gt;

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


&lt;p&gt;If you guys want to read a more amazing blog about this topic, please check on Sean posts.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/seanwelshbrown" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--12ITcR9F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--Z2o0Sypv--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/316463/bac9c958-0a1e-4d7a-9fc9-e13149b74d82.jpeg" alt="seanwelshbrown image"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/seanwelshbrown/find-the-first-duplicate-in-a-javascript-array-5da3" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Find the First Duplicate in a JavaScript Array&lt;/h2&gt;
      &lt;h3&gt;Sean Welsh Brown ・ Aug  5 ・ 4 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#algorithms&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#arrays&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;




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

&lt;p&gt;We are just beginning to cover early on on Data Structures and so far we seen Big O and Arrays. We mentioned how dynamic arrays have to double up or expand our memory. Also how strings are considered array questions. It's recommended to go and cheat the Big O cheat sheet and read more the section regards array (interpret / understand). This will help you more by the time we get into Algorithms. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qFs4DSx_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.pinimg.com/originals/ba/73/d4/ba73d439fcf393a791abd101d587c58f.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qFs4DSx_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.pinimg.com/originals/ba/73/d4/ba73d439fcf393a791abd101d587c58f.gif" alt="running"&gt;&lt;/a&gt;&lt;/p&gt;
See you next time ~~~ Bye.



</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>algorithms</category>
      <category>challenge</category>
    </item>
    <item>
      <title>Intro to Data Structures + Algo [Part 1]</title>
      <dc:creator>Miguel Ben</dc:creator>
      <pubDate>Mon, 03 Aug 2020 02:57:36 +0000</pubDate>
      <link>https://dev.to/migben/intro-to-data-structures-algo-part-1-559o</link>
      <guid>https://dev.to/migben/intro-to-data-structures-algo-part-1-559o</guid>
      <description>&lt;p&gt;Hey folks! I'm starting a series to cover popular code challenges that are often used on technical interviews. My intent is to make this a weekly series and that way we could share our solutions in the comments. As a reference many of these challenges are taken from websites such as &lt;a href="https://www.hackerrank.com"&gt;Hackerrank&lt;/a&gt;, &lt;a href="https://leetcode.com"&gt;Leetcode&lt;/a&gt;, &lt;a href="https://www.interviewcake.com"&gt;InterviewCake&lt;/a&gt; and &lt;a href="https://www.codewars.com"&gt;Codewars&lt;/a&gt;. (etc...)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Data Structures?&lt;/strong&gt; Well, it is a particular way of organizing data in a computer/program so that it can be used effectively. Then, &lt;strong&gt;What is an algorithm?&lt;/strong&gt; is a step-by-step procedure that takes an input instance (problem) as input/s and produces output for the problem (instance).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Warning&lt;/strong&gt;: It's not guaranteed that you will be asked any of the coding or data structure / algorithmic questions, but they will give you an idea of what kind of questions you can expect in a real interview.&lt;/p&gt;

&lt;p&gt;If you have no experience whatsoever in Data Structure and Algorithms, then you should visit either interview cake, Udemy Colt Steele or even Freecodecamp to get the basics down.&lt;/p&gt;

&lt;p&gt;My intention is to cover the following during this series:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Big O&lt;/strong&gt; &lt;a href="https://www.bigocheatsheet.com"&gt;🔗&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Arrays&lt;/strong&gt; &lt;a href="https://www.geeksforgeeks.org/array-data-structure/"&gt;🔗&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Linked list&lt;/strong&gt; &lt;a href="https://www.geeksforgeeks.org/data-structures/linked-list/"&gt;🔗&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stacks &amp;amp; Queues&lt;/strong&gt; &lt;a href="https://everythingcomputerscience.com/discrete_mathematics/Stacks_and_Queues.html#:~:text=Stack%20is%20a%20container%20of,-out%20(FIFO)%20principle."&gt;🔗&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hashes&lt;/strong&gt; &lt;a href="https://www.geeksforgeeks.org/hashing-data-structure/"&gt;🔗&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sorting&lt;/strong&gt; &lt;a href="https://www.geeksforgeeks.org/sorting-algorithms/"&gt;🔗&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trees&lt;/strong&gt; (Binary Search Tree) &lt;a href="https://www.geeksforgeeks.org/binary-tree-data-structure/"&gt;🔗&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Graphs&lt;/strong&gt; &lt;a href="https://www.geeksforgeeks.org/graph-data-structure-and-algorithms/"&gt;🔗&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;System Design&lt;/strong&gt; (Extra) &lt;a href="https://www.quora.com/What-do-you-mean-by-System-Design#:~:text=Systems%20design%20is%20the%20process%20of%20defining%20the%20architecture%2C%20components,system%20to%20satisfy%20specified%20requirements.&amp;amp;text=Systems%20design%20is%20the%20process%20of%20defining%20the%20architecture%2C%20modules,system%20to%20satisfy%20specified%20requirements."&gt;🔗&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: Challenges will be presented like this =&amp;gt; e.g: Big-O (Title) [Difficulty]&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/y3QOvy7xxMwKI/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/y3QOvy7xxMwKI/giphy.gif" alt="think"&gt;&lt;/a&gt;&lt;/p&gt;
Umm... wait a minute, what about the types of Alg?



&lt;p&gt;Ah...yes. Before I forget, All algorithms can be categorized in one of these paradigms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Brute Force Algorithm&lt;/strong&gt; - check all possible solutions and select the best one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Programming Alg.&lt;/strong&gt; - solve the problem based on all the previous solutions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Greedy&lt;/strong&gt; - Choosing the best solution at the moment, regardless of the consequences in the future.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Divide &amp;amp; Conquer&lt;/strong&gt; - divide the problem into a smaller set of issues to resolve and get the overall solution at the end.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's begin introducing our first guest &lt;strong&gt;Big O&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Big O
&lt;/h2&gt;

&lt;p&gt;Allows us to determine the scalability of our code, this refers to how we measure the efficiency of our code. How can we exactly calculate the performance of our code? is it runtime speed? complexity/simplicity? Regardless the differences of our computer how do we calculate scalability again? We are able to measure it by how large the input size is and how much this slow down our function or algorithm (algorithmic efficiency).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IOJhpC9V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/v9tosyl6k7tk04drf1bs.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IOJhpC9V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/v9tosyl6k7tk04drf1bs.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
As the number of elements(inputs) increases, how many operations do we have to do? 


&lt;h3&gt;
  
  
  Linear Time
&lt;/h3&gt;


&lt;div class="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;yoda&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Baby Yoda&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;friends&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Mandolorian&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Luke&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Leila&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Clone 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="s1"&gt;Baby Yoda&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dark Vader&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;large&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Baby Yoda&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;findBabyYoda&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&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;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="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="k"&gt;if&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="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Baby Yoda&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;FOUND YODA!&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="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;findBabyYoda&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;friends&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// O(n) - Linear time&lt;/span&gt;
&lt;span class="c1"&gt;// The num of outputs increases proportionally with the num of inputs&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Constant Time
&lt;/h3&gt;


&lt;div class="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;pineapples&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="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&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;logFirstsPineapples&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;pineapples&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;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;pineapples&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;  &lt;span class="c1"&gt;// O(1) - constant time&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;pineapples&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="c1"&gt;// 0(1) - constant time&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="nx"&gt;logFirstsPineapples&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pineapples&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// O(2) &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;1- What is the Big O of the below function? &lt;a href="https://repl.it/join/sogirdpt-mius00"&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;firstChallenge&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;input&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&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;input&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="nx"&gt;ramdomFunction&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;stranger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&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;2- What is the Big O of the below function? &lt;a href="https://repl.it/@Mius00/BigO"&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;secondChallenge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;50&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;input&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&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="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="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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;z&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;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;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;input&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&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;q&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;*&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;whoRu&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I don't know&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Rules to help you Big(O) a bit better:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Worst Case&lt;/strong&gt;: &lt;/p&gt;



&lt;h4&gt;
  
  
  Resource
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.bigocheatsheet.com"&gt;Big 0 Spreadsheet&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/ACLCA6bvwBEvC/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/ACLCA6bvwBEvC/giphy.gif" alt="labyrinth"&gt;&lt;/a&gt;&lt;/p&gt;
are you still with me?



&lt;p&gt;Thanks for making it to the end of our first stop, what we saw today seemed pretty basic but this is only the beginning and it will get more challenging as we progress in this topic. If you have any questions, suggestions or anything to discuss in regards this topic please comment below.&lt;/p&gt;

&lt;p&gt;Hope to see you in the comments!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>algorithms</category>
      <category>challenge</category>
    </item>
    <item>
      <title>// How to deploy your front end website.</title>
      <dc:creator>Miguel Ben</dc:creator>
      <pubDate>Thu, 20 Feb 2020 19:38:39 +0000</pubDate>
      <link>https://dev.to/migben/how-to-deploy-your-front-end-website-3mlg</link>
      <guid>https://dev.to/migben/how-to-deploy-your-front-end-website-3mlg</guid>
      <description>&lt;p&gt;Hey folks, today we are going to talk about how to deploy that front-end project that you have been working on. As newbies we often think "How can I make my work accessible to the world?". Don't be discouraged it's simpler than you may think! &lt;/p&gt;

&lt;p&gt;So, I've found some options for our dilemma which are the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://surge.sh/"&gt;surge.sh&lt;/a&gt; 🍄 + 🦵&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://pages.github.com/"&gt;github-pages&lt;/a&gt; 😸 + 🐙&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.netlify.com/"&gt;netlify.com&lt;/a&gt; ⚡️&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/giEftvZuPAiZQBphEI/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/giEftvZuPAiZQBphEI/giphy.gif" alt="options"&gt;&lt;/a&gt;&lt;/p&gt;
Our boy Heroku is not an option here...💨



&lt;h2&gt;
  
  
  Deploying with Surge
&lt;/h2&gt;

&lt;p&gt;Surge is a simple, single-command web publishing CLI library. It can publish HTML, CSS, and JS for &lt;strong&gt;free&lt;/strong&gt;, without leaving the command line. Everything becomes so simple that you are actually a few key strokes away from deploying your website or web app with the help of &lt;a href="https://nodejs.org/en/"&gt;&lt;code&gt;node.js&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Ensure that you have the latest version of node.js installed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install Surge: &lt;br&gt;
   &lt;code&gt;npm install --global surge&lt;/code&gt; or &lt;code&gt;npm install -g surge&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to your project root folder, run &lt;code&gt;surge&lt;/code&gt; and fill the project path and domain field (&lt;em&gt;optional&lt;/em&gt;). &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KpY3cqc2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://surge.sh/images/help/getting-started-with-surge.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KpY3cqc2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://surge.sh/images/help/getting-started-with-surge.gif" alt="deployit"&gt;&lt;/a&gt;&lt;/p&gt;
Note: Surge by default provides a domain for your project.



&lt;p&gt;One more thing, while deploying your site with &lt;code&gt;surge&lt;/code&gt; you will be asked for an email and password, type an email / password of your choice (&lt;em&gt;easy to remember&lt;/em&gt;). This is the default domain that surge generated for me &lt;a href="http://like-clouds.surge.sh/"&gt;http://like-clouds.surge.sh/&lt;/a&gt; .&lt;/p&gt;

&lt;h3&gt;
  
  
  Deploy with a custom domain
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;WARNING:&lt;/strong&gt; This may require some extra steps in terms of configuring your DNS but for more details please refer to the official guide from Surge &lt;a href="https://medium.com/surge-sh/make-something-of-your-ridiculous-domains-bb26fadeb93c"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or click here: &lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/surge-sh/make-something-of-your-ridiculous-domains-bb26fadeb93c" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h_nWf-gQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/fit/c/96/96/1%2Af176FwUVQb4eZ43Ik5g8nw.jpeg" alt="Kenneth Ormandy"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/surge-sh/make-something-of-your-ridiculous-domains-bb26fadeb93c" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Make something of your ridiculous domains | by Kenneth Ormandy | surge sh | Medium&lt;/h2&gt;
      &lt;h3&gt;Kenneth Ormandy ・ &lt;time&gt;Oct 21, 2015&lt;/time&gt; ・ 5 min read
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KBvj_QRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/medium_icon-90d5232a5da2369849f285fa499c8005e750a788fdbf34f5844d5f2201aae736.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;After the necessary setup, Surge will allow you to deploy your site with a custom domain by using the following command:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;$ surge ./ *customdomainname.com*&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A quick breakdown of the command + optional args used: &lt;code&gt;$&lt;/code&gt; prompt, &lt;code&gt;./&lt;/code&gt; root of your project path, and &lt;code&gt;*customdomainname.com*&lt;/code&gt; your custom domain name.&lt;/p&gt;



&lt;h2&gt;
  
  
  Deploying with Github pages
&lt;/h2&gt;

&lt;p&gt;Many may argue with me, but github pages is the way to go for deploying static sites. Why? If you already have a github account, a static site and your git terminal set up, then you are a few steps away from having your site deployed. &lt;/p&gt;

&lt;p&gt;Steps:&lt;/p&gt;

&lt;p&gt;A. Already have your own &lt;a href="https://github.com/"&gt;Github&lt;/a&gt; account and create a new github repo with the name: &lt;code&gt;username.github.io&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LNLtVZiM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/2MWwXat.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LNLtVZiM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/2MWwXat.png" alt="creatnew"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;B. Jump to your git terminal client (&lt;em&gt;recommended&lt;/em&gt;) and clone your new repo to a local directory. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1_rFc8kx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/Oq1DvCt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1_rFc8kx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/Oq1DvCt.png" alt="gitclone"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;C. Enter the project folder and add an index.html file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sLDgzdeT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/FIb1CEe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sLDgzdeT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/FIb1CEe.png" alt="cdThenEchoCreate"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;D. Push everything up to Github:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dpMIZLxr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/JksAJN3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dpMIZLxr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/JksAJN3.png" alt="Pushit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;E. …and you're done, fire up your browser and visit your site at &lt;code&gt;https://username.github.io&lt;/code&gt; &lt;/p&gt;



&lt;h2&gt;
  
  
  Deploying with Netlify
&lt;/h2&gt;

&lt;p&gt;For last, we have Netlify a web hosting infrastructure and automation technology. why &lt;a href="https://www.netlify.com/github-pages-vs-netlify/"&gt;Netlify&lt;/a&gt; instead GithubPages or even Surge.sh? Netlify provides you with basic features such as website deploy preview, site state rollbacks and other management tools for free.&lt;/p&gt;

&lt;p&gt;Steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sign up to Netlify and add a new site (&lt;em&gt;project&lt;/em&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EhUhAjXP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.netlify.com/ef2fd8809717bbf8c7a16ac2862c19bb12f717b5/ef6e8/img/blog/add-new-project.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EhUhAjXP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.netlify.com/ef2fd8809717bbf8c7a16ac2862c19bb12f717b5/ef6e8/img/blog/add-new-project.png" alt="addNewProject"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Right after, logging in you'll be prompted with the &lt;strong&gt;Add A New Project&lt;/strong&gt; button shown above. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Link your Github account&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6bZu6xq0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.netlify.com/6ce8bf46dcc8bfc6d6ef982c7870eb86e32d2b8c/89152/img/blog/step-2-hugo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6bZu6xq0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.netlify.com/6ce8bf46dcc8bfc6d6ef982c7870eb86e32d2b8c/89152/img/blog/step-2-hugo.png" alt="linkScreen"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Make sure your static website or SPA has been pushed to Github, so we'll connect netlify with github. Just click the button with the familiar octo cat icon.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authorize Netlify&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u1tHyOFK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloud.githubusercontent.com/assets/6520639/9803635/71760370-57d9-11e5-8bdb-850aa176a22c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u1tHyOFK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloud.githubusercontent.com/assets/6520639/9803635/71760370-57d9-11e5-8bdb-850aa176a22c.png" alt="Authorize"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Allow Netlify and GitHub to talk to each other by clicking the Authorize Application button.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select Your Repo&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jLtM666r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloud.githubusercontent.com/assets/6520639/9897552/b9ea7f7c-5bfe-11e5-94a0-f957a7d1986e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jLtM666r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloud.githubusercontent.com/assets/6520639/9897552/b9ea7f7c-5bfe-11e5-94a0-f957a7d1986e.png" alt="selectingRepo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After connecting Github and Netlify, choose the repo with your static or SPA files.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Configure Your Settings&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j00z5rWi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.netlify.com/80976208deb6958b0fd438cb961a63d95a259f07/c1ae2/img/blog/config-your-repo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j00z5rWi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.netlify.com/80976208deb6958b0fd438cb961a63d95a259f07/c1ae2/img/blog/config-your-repo.png" alt="configB4Deploy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If necessary you can configure your options on this step. If your site is static and is not using any preprocessors or compiling software then just set the directory to / or just &lt;code&gt;leave the build command blank&lt;/code&gt;. Now click the &lt;strong&gt;Build your site button&lt;/strong&gt; to &lt;em&gt;continue&lt;/em&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build Your Site and Visit your site&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DdFrH5qf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.netlify.com/8f58588b14e3136d2885c3df9875b1b5b8e72f51/0a39b/img/blog/building-site.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DdFrH5qf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.netlify.com/8f58588b14e3136d2885c3df9875b1b5b8e72f51/0a39b/img/blog/building-site.png" alt="compiling"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sit and chill, while netlify is taking care of everything.&lt;/p&gt;

&lt;h3&gt;
  
  
  References:
&lt;/h3&gt;

&lt;p&gt;These are the resources I've used for this post:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://surge.sh/"&gt;surge.sh&lt;/a&gt; | &lt;a href="https://www.youtube.com/watch?v=-EjdMvYPSVU&amp;amp;feature=emb_title"&gt;YT-DeployWithSurge&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://pages.github.com/"&gt;github-pages&lt;/a&gt; | &lt;a href="https://www.youtube.com/watch?time_continue=81&amp;amp;v=2MsN8gpT6jY&amp;amp;feature=emb_title"&gt;YT-GithubPages?&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.netlify.com/blog/2016/10/27/a-step-by-step-guide-deploying-a-static-site-or-single-page-app/"&gt;netlify.com - Deploy guide&lt;/a&gt; | &lt;a href="https://www.youtube.com/watch?v=mN9oI98As_4"&gt;YT-NetlifyInSecs&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Recap:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Surge, is ease the installation and launching process, while hosting your static site locally. It generates a random domain name for your project by default.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Github pages allows us to host our static site on their platform but domain names have the following format &lt;code&gt;projectname.github.io&lt;/code&gt;. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Netlify does also allow you to host static sites on their platform and offer a lots of perks in regards managing your project but it whats made for more complex and robust web apps in mind.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Anything else?
&lt;/h3&gt;

&lt;p&gt;Did I miss something? Need to clarify or discuss? Please let me know in the comments!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/26xBNV7I1IvN0PHX2/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/26xBNV7I1IvN0PHX2/giphy.gif" alt="deep thinking"&gt;&lt;/a&gt;&lt;/p&gt;
 It feels like I missed something ...



</description>
      <category>tutorial</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>// Let's learn `this` in Javascript</title>
      <dc:creator>Miguel Ben</dc:creator>
      <pubDate>Mon, 10 Feb 2020 21:36:13 +0000</pubDate>
      <link>https://dev.to/migben/let-s-learn-this-in-javascript-1ij2</link>
      <guid>https://dev.to/migben/let-s-learn-this-in-javascript-1ij2</guid>
      <description>&lt;p&gt;Hello World,&lt;/p&gt;

&lt;p&gt;Today we will be going over the javascript keyword &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this" rel="noopener noreferrer"&gt; &lt;code&gt;this&lt;/code&gt;&lt;/a&gt; (clickable). The value of &lt;code&gt;this&lt;/code&gt; refers to the object that is executing at the current function (runtime binding). This topic often confuses a plethora of developers because it's one of the most commons JS keywords, but it's hard to tell what does &lt;code&gt;this&lt;/code&gt; means. &lt;/p&gt;

&lt;p&gt;I'm assuming that you already know what an object, and a method is. However, if you are feeling rusty let's do a quick recap: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is an object?&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;is a set of data stored in name-value pairs (Hashes or key-value pairs).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Example of an obj: 👇&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;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Greg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;power_level&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;hobby&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cycling&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;unknown&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;skill_user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;


&lt;p&gt;In an obj you are able to store values such as string, integers, booleans, functions and even other objects.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is a method?&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;is a function that belongs to an object.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&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;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;word&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alright!~&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="na"&gt;shouting&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;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="s1"&gt;Hey Luke!! wink wink ~&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="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shouting&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// =&amp;gt; Hey Luke!! wink wink ~&lt;/span&gt;

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

&lt;/div&gt;


&lt;p&gt;In the prior example &lt;code&gt;shouting&lt;/code&gt; is a method of our person object.&lt;/p&gt;
&lt;h2&gt;
  
  
  Qué es esto / this? 🧐
&lt;/h2&gt;

&lt;p&gt;Again, in the context of JS 'this' refers to the object that our function belongs to. An example of &lt;code&gt;this&lt;/code&gt; could be our person obj inside a function:&lt;/p&gt;

&lt;p&gt;Example 1:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Isaac&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;routine&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// `this` refers to the current instance | object called person&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;routine&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// =&amp;gt; { name: 'Isaac', routine: [Function: routine] }&lt;/span&gt;

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

&lt;/div&gt;


&lt;p&gt;Executing the code above will let us see the person object.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;gt; typeof person
  &amp;gt; 'object'

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

&lt;/div&gt;


&lt;p&gt;Example 2:&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;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;power_level&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="na"&gt;afterTraining&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="c1"&gt;// camel case&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;power_level&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;300&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="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="s1"&gt;initial power level of &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;power_level&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; initial power level of 25.&lt;/span&gt;

&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;afterTraining&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// =&amp;gt; +300&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="s1"&gt;Power after training: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;power_level&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; Power after training: 325.&lt;/span&gt;

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

&lt;/div&gt;


&lt;p&gt;As we can see the &lt;code&gt;afterTraining&lt;/code&gt; function increases the &lt;code&gt;power_level&lt;/code&gt; by 300.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/7SKOwf1nD6j6XhfLMG/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/7SKOwf1nD6j6XhfLMG/giphy.gif" alt="self-trip?"&gt;&lt;/a&gt;&lt;/p&gt;
Hey bud! are you still w/ me?


&lt;h3&gt;
  
  
  Global context
&lt;/h3&gt;

&lt;p&gt;If we type &lt;code&gt;this&lt;/code&gt; in our browser console, it will refer to window - global object. &lt;strong&gt;Chrome:&lt;/strong&gt; Press &lt;code&gt;⌘ + ⇧ + C&lt;/code&gt; to access the browser console.&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;this&lt;/span&gt; &lt;span class="c1"&gt;// =&amp;gt; Window obj&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, World!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hello&lt;/span&gt; &lt;span class="c1"&gt;// =&amp;gt; Hello, World!&lt;/span&gt;

&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heyCarl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hey, Carl.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heyCarl&lt;/span&gt; &lt;span class="c1"&gt;// =&amp;gt; Hey, Carl.&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;helloFix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello...repairman&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;helloFix&lt;/span&gt; &lt;span class="c1"&gt;// =&amp;gt; und ... undefined?&lt;/span&gt;

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

&lt;/div&gt;

&lt;h2&gt;
  
  
  Recap: 🔍
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;By default &lt;code&gt;this&lt;/code&gt; gets set to "window" obj, unless declared as something else.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;this&lt;/code&gt; is the obj that our function belongs to when called.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading 👋. Hey check out one of my friends blog:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Shoutout Round 1&lt;/strong&gt;&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/iqramqra" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F325896%2F7828b82e-46af-45cb-8805-01386f168aef.jpg" alt="iqramqra"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/iqramqra/releasing-your-inner-unicorn-3a0e" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Releasing Your Inner Unicorn&lt;/h2&gt;
      &lt;h3&gt;Iqra Masroor ・ Jan 28 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#lolcat&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#rubygem&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#cli&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#ruby&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;




&lt;div class="ltag__link"&gt;
  &lt;a href="/loripb" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F328552%2Fc6078463-aa3d-4be0-ae33-21724f258dd1.jpeg" alt="loripb"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/loripb/an-example-of-a-git-workflow-kje" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;An Example of a Git Workflow&lt;/h2&gt;
      &lt;h3&gt;Lori "Lei" Boyd ・ Feb 3 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#git&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/@lukelin1991/ive-been-working-on-the-rails-road-319721f25f61" class="ltag__link__link" rel="noopener noreferrer"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fv2%2Fda%3Atrue%2Fresize%3Afill%3A88%3A88%2F0%2AjKu0t6aWOWayFMZq" alt="Luke Lin"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/@lukelin1991/ive-been-working-on-the-rails-road-319721f25f61" class="ltag__link__link" rel="noopener noreferrer"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;I’ve been working on the “Rails” road! How to Rails through your terminal. This is only the beginning… | by Luke Lin | Medium&lt;/h2&gt;
      &lt;h3&gt;Luke Lin ・ &lt;time&gt;Feb 10, 2020&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&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%2Fassets%2Fmedium-f709f79cf29704f9f4c2a83f950b2964e95007a3e311b77f686915c71574fef2.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  References:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this" rel="noopener noreferrer"&gt; MDN - this&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=gvicrj31JOM" rel="noopener noreferrer"&gt;JS on 'this' (YT)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Anything else?
&lt;/h2&gt;

&lt;p&gt;Did I miss something? Please let me know in the comments!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/bznNJlqAi4pBC/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/bznNJlqAi4pBC/giphy.gif" alt="Great!"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Yay!&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;By the way this was my first post! 🎉🎉🎉&lt;/p&gt;
&lt;/blockquote&gt;

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