<?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: Seth</title>
    <description>The latest articles on DEV Community by Seth (@seth_king).</description>
    <link>https://dev.to/seth_king</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%2F785425%2F3453d4d2-765c-4421-b84c-c22568224e8e.jpg</url>
      <title>DEV Community: Seth</title>
      <link>https://dev.to/seth_king</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/seth_king"/>
    <language>en</language>
    <item>
      <title>Roman to Integer</title>
      <dc:creator>Seth</dc:creator>
      <pubDate>Wed, 06 Apr 2022 02:51:38 +0000</pubDate>
      <link>https://dev.to/seth_king/roman-to-integer-4a3o</link>
      <guid>https://dev.to/seth_king/roman-to-integer-4a3o</guid>
      <description>&lt;p&gt;This one is similar to the Integer to Roman one, but it has some differences.&lt;/p&gt;

&lt;p&gt;Let's begin by creating a map of our values as we will need to be able to reference these later. When we have this map handy, we can reference it when looking at every letting in the string. Here's a few string examples to keep in mind too: XIX,   XI which is 19 and 11.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function romanToInteger(string) {
 let map = {
     I: 1,
     V: 5,
     X: 10,
     L: 50,
     C: 100,
     D: 500,
     M: 1000,
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next we will loop through the string and assign each letter as either current or next. &lt;/p&gt;

&lt;p&gt;In XI, or 11, the current is X and the next is I.&lt;/p&gt;

&lt;p&gt;If the current letter is greater than the next, we can add it to our result normally.&lt;/p&gt;

&lt;p&gt;In the case of XI, we can add 10 and then next, which is 1 and get 11. &lt;/p&gt;

&lt;p&gt;If the current letter is less than the next one, as is the case in 20, XIX, we want to subtract the next element by the current element.&lt;/p&gt;

&lt;p&gt;So, imagine this. Looking at XIX, current is X and next is I. Since X is greater then I, we add X. Then we look at I and X, the current isn't greater than the next, so we add the values of next minus the current or 10 - 1. &lt;/p&gt;

&lt;p&gt;This gets up to 19.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function romanToInteger(string) {
 let map = {
     I: 1,
     V: 5,
     X: 10,
     L: 50,
     C: 100,
     D: 500,
     M: 1000,
 }
  let result = 0
  for (let i = 0; i &amp;lt; string.length; i++) {
   let current = map[string.charAt(i)]
   let next = map[string.charAt(i+1)]
    if (current &amp;gt; next) {
   result += current
  } else {
   result += next - current
   }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should handle most cases except for the last case, which is when we are at the end of the string and there are no more next elements to review.&lt;/p&gt;

&lt;p&gt;In this case, we wrap all the if statements under a new if statement, that says as long as there is a next statement, run these if statements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function romanToInteger(string) {
 let map = {
     I: 1,
     V: 5,
     X: 10,
     L: 50,
     C: 100,
     D: 500,
     M: 1000,
 }
  let result = 0
  for (let i = 0; i &amp;lt; string.length; i++) {
   let current = map[string.charAt(i)]
   let next = map[string.charAt(i+1)]

    if (next) {
    if (current &amp;gt; next) {
   result += current
  } else {
   result += next - current
   }
  }
 } else {
  result += current
 }
return result
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there we've got it folks.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Integer to Roman</title>
      <dc:creator>Seth</dc:creator>
      <pubDate>Sun, 20 Mar 2022 18:07:45 +0000</pubDate>
      <link>https://dev.to/seth_king/integer-to-roman-oc7</link>
      <guid>https://dev.to/seth_king/integer-to-roman-oc7</guid>
      <description>&lt;p&gt;We'er going to kick things off by creating 2 variables. One will store our numbers, and the other will store the corresponding roman numeral, and both will go from highest to lowest. &lt;/p&gt;

&lt;p&gt;This will allow us to associate a number with its counterpart. &lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;Remember to put each number and roman numeral as a string within the overall array.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    let numbers = ['1000', '900', '500', '400', '100', '90', '50', '40', '10', '9', '5', '4', '1']
    let romans = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
    let result = ''

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

&lt;/div&gt;



&lt;p&gt;Now that we have this dict ready, we can loop through the number and find out if the number given is greater than the current number.&lt;/p&gt;

&lt;p&gt;If it is, we will add the corresponding roman numeral to a result variable, then we will subtract the given number by the current number. &lt;/p&gt;

&lt;p&gt;We will continue to do this loop until we are 0 and then we return the result string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    let numbers = ['1000', '900', '500', '400', '100', '90', '50', '40', '10', '9', '5', '4', '1']
    let romans = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
    let result = ''

     //loop through numbers
     for (let i = 0; i &amp;lt; numbers.length; i++){

         //set variable to current number
         let current = numbers[i]

         //while the number equal the current number or is 
          bigger then it 
         while (num &amp;gt;= current) {


            //add the corresponding numeral to the result 
             string
             result += romans[i]

              //subtract the num by the current current in the 
              numbers array
             num-=current
         }
     }

       //return the result
    return result
};

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

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Max Water Container</title>
      <dc:creator>Seth</dc:creator>
      <pubDate>Sun, 20 Mar 2022 17:09:54 +0000</pubDate>
      <link>https://dev.to/seth_king/max-water-container-4poe</link>
      <guid>https://dev.to/seth_king/max-water-container-4poe</guid>
      <description>&lt;p&gt;Let's observe the logic behind the chart we're seeing.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qQLl72cK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tw1fqmqpbo29oayw8nef.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qQLl72cK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tw1fqmqpbo29oayw8nef.png" alt="Image description" width="880" height="611"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The area, and the answer, is 49. &lt;/p&gt;

&lt;p&gt;We got that number because we looked at the distance between the two indices and then multiplied it by the minimum value of both indices. &lt;/p&gt;

&lt;p&gt;Let's look at the first part, the width, since finding an area is width times height.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;result = (j-i)*min(height[j], height[i])
         ______
           7

 height = [1,8,6,2,5,4,8,3,7]
             _             _
             1             8

   8-1 = 7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's look at the second part. The height.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;result = (j-i)*min(height[j], height[i])
                ___________________
                   7

 height = [1,8,6,2,5,4,8,3,7]
             _             _
             8             7

  min(7, 8) = 7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And let's do the last step just for kicks, multiplying them together, then we'll jump into code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;result = (j - i)*min(height[j], height[i])
          ___________________  _________________________
              7             *             7
           **= 49**

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

&lt;/div&gt;



&lt;p&gt;And that is how we will get our answer. &lt;/p&gt;

&lt;p&gt;The first thing we want is to declare variables. i is at the left, and j is at the right.&lt;/p&gt;

&lt;p&gt;Then we will want them to move left and right.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
function maxWater (array) {
 let i = 0
 let j = array.length - 1
 let area = 0

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

&lt;/div&gt;



&lt;p&gt;Now let start iterating through the array, and we will do so with a while loop until the two pointers meet each other.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
function maxWater (array) {
 let i = 0
 let j = array.length - 1
 let area = 0

 while (i &amp;lt; j) {
   const temp = (j - i).Math.min(array[j], array[i])

 }

}

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

&lt;/div&gt;



&lt;p&gt;Then we update the area and move the i and j. It's not helpful to move the larger number in this case, so we only move the lower number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
function maxWater (array) {
 let i = 0
 let j = array.length - 1
 let area = 0

 while (i &amp;lt; j) {
   const temp = (j - i).Math.min(array[j], array[i])
   area = Math.max(temp, area)
   if (array[i] &amp;gt; array[j]) {
    array[j]-=1
   } 
     else {
   array[i]+=1
  }
 }
 return area
}

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

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>String to integer aloi</title>
      <dc:creator>Seth</dc:creator>
      <pubDate>Sat, 19 Mar 2022 18:28:09 +0000</pubDate>
      <link>https://dev.to/seth_king/string-to-inter-aloi-3o42</link>
      <guid>https://dev.to/seth_king/string-to-inter-aloi-3o42</guid>
      <description>&lt;p&gt;Lets say the string we are given is '4123'. Lets's start by figuring out how we are going to get to that number itself.&lt;/p&gt;

&lt;p&gt;This way is cheeky. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When we look at any number we can do the first number times 10 plus then 2nd number. In this case
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;((4 * 10 + 1)* 10 + 2) * 10 + 3)
________
  {41}
((4 * 10 + 1)* 10 + 2) * 10 + 3)
________________
  {410}
((4 * 10 + 1)* 10 + 2) * 10 + 3)
______________________
        {412}
((4 * 10 + 1)* 10 + 2) * 10 + 3)
_________________________________
                   {4123)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every time we multiply the number by ten we get a 0 in place that we can then change using addition. We keep adding numbers to the right hand side each iteration until we've got the entire number.&lt;/p&gt;

&lt;p&gt;Another way to look at it is this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;41 -&amp;gt;
410 -&amp;gt; 
 +12 -&amp;gt;
____
412. 
*10 -&amp;gt;
4120
  +3 -&amp;gt;
____
4123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's get into how we're going to solve this problem. It's very simple with the code, and you'll be kicking yourself if you've been struggling with it once you see it.&lt;/p&gt;

&lt;p&gt;1) turn the str into a number with parseInt method&lt;br&gt;
2) if the number isn't a number, return 0&lt;br&gt;
3) if the number is less then the lower bound, return the lower bound&lt;br&gt;
4) if the number is greater the the higher bound, return the higher bound&lt;br&gt;
5) if we don't hit any of these condition return the parseInt'd number&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const aloi = (str) =&amp;gt; {
 let num = parseInt(str) 
 if (Number.isNaN(num)){
 return 0
}
 if (num &amp;lt; -2**31) {
 return -2**31
}
 if (num &amp;gt; 2**31-1) {
 return 2**31-1
}
 return num
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Reverse Integer</title>
      <dc:creator>Seth</dc:creator>
      <pubDate>Sat, 19 Mar 2022 03:26:51 +0000</pubDate>
      <link>https://dev.to/seth_king/reverse-integer-33p7</link>
      <guid>https://dev.to/seth_king/reverse-integer-33p7</guid>
      <description>&lt;p&gt;Don't get scared when it tells you that the integer is 32 bit. I had no idea what this was at first, but it just means the number has an upper bound and an lower bound number, meaning there are limits to its largest and lowest numbers.&lt;/p&gt;

&lt;p&gt;We will start with the base case.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const reverse = (x) =&amp;gt; {
 if (x &amp;lt; 0) return -1 * reverse(-x)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This line is important. If the number is negative, we will want to turn it into a positive number so we can break out of the if loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const reverse = (x) =&amp;gt; {
 if (x &amp;lt; 0) return -1 * reverse(-x)
 const solution = x.toString().split('').reverse().join('')

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

&lt;/div&gt;



&lt;p&gt;Next we will turn the number into a string, split it, reverse, then join it back together. &lt;/p&gt;

&lt;p&gt;Now let's finish it out.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const reverse = (x) =&amp;gt; {
 if (x &amp;lt; 0) return -1 * reverse(-x)
 const solution = x.toString().split('').reverse().join('')

 if (solution &amp;gt; 2 ** 31 - 1) {
  return 0
  } 
  else {
 return solution
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The number has an upper bound of 2^31 -1. So, if the solution is greater than the upper bound we return 0. This is because it's too large to be in the bounds of our answer. &lt;/p&gt;

&lt;p&gt;If it's less, we can just return the solution.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>career</category>
    </item>
    <item>
      <title>Zigzag Direction</title>
      <dc:creator>Seth</dc:creator>
      <pubDate>Fri, 18 Mar 2022 01:07:44 +0000</pubDate>
      <link>https://dev.to/seth_king/zigzag-direction-bim</link>
      <guid>https://dev.to/seth_king/zigzag-direction-bim</guid>
      <description>&lt;p&gt;We've got 2 parameters in this function: a string, and then a certain number of rows. &lt;/p&gt;

&lt;p&gt;For example, 'PAYPALISHIRING' is the final result we want to get. But in order to get there, we need to separate it by the number of rows and join the rows together.&lt;/p&gt;

&lt;p&gt;P   A   H   N&lt;br&gt;
A P L S I I G&lt;br&gt;
Y   I   R&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var convert = function(s, numRows) {

    if (s.length &amp;lt; 2 || s.length &amp;lt; numRows){
        return s
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looking at this first part, we are just saying if the length is only 1 letter or if the amount of letters is less than the amount of rows, just return the letter. This certifies our base condition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var convert = function(s, numRows) {

    if (s.length &amp;lt; 2 || s.length &amp;lt; numRows){
        return s
    }

    const rows = new Array(numRows).fill('')
    let count = 0
    let reverse = false;

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

&lt;/div&gt;



&lt;p&gt;Now we will set ourselves up for success. We are going to create a new array for the amount rows there are and will fill it with an empty string. If we consoled logged here with numRows = 3, it'd look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var convert = function(s, numRows) {

    if (s.length &amp;lt; 2 || s.length &amp;lt; numRows){
        return s
    }

    const rows = new Array(numRows).fill('')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we console log rows, we get this below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;['']['']['']

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

&lt;/div&gt;



&lt;p&gt;Next, we need a counter variable of 0, since we will later traverse the string and let each letter sit in an Array. Then, if the count is 0, or equal to the number of rows, we change direction. &lt;/p&gt;

&lt;p&gt;Since we go left to right, we will hit the numRows before we hit 0 (the first letter in the first array is at 1, not 0, so we will want to say if reverse is true, then decrement down). If it's false, then keep going forward.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var convert = function(s, numRows) {

    if (s.length &amp;lt; 2 || s.length &amp;lt; numRows){
        return s
    }

    const rows = new Array(numRows).fill('')
    let count = 0
    let reverse = false;

    for (let i = 0; i &amp;lt; s.length; i++) {
    rows[count] += s[i]
    reverse ? count-- : count++
    if (count === 0 || count === numRows - 1) {
       reverse = !reverse
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we console log here, we can see the following happen: At the first array, we get the current letter and so on until we hit the 3rd letter. Then reverse changes course so the A, string 2, gets the next letter and we go down until we hit 1 and then&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ 'P', '', '' ]
   -
   1
[ 'P', 'A', '' ]
        -
        2
[ 'P', 'A', 'Y' ]
             -
             3
[ 'P', 'AP', 'Y' ]
        -
        2
[ 'PA', 'AP', 'Y' ]
   -
   1
[ 'PA', 'APL', 'Y' ]
          -
          2
[ 'PA', 'APL', 'YI' ]
                - 
                3
[ 'PA', 'APLS', 'YI' ]
           -
           2 
[ 'PAH', 'APLS', 'YI' ]
    -
    1

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

&lt;/div&gt;



&lt;p&gt;And on and on we go, but we can see that when we hit one end we zag. If we hit the other way then we zig. The only thing left is to join all the rows together and return it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var convert = function(s, numRows) {

    if (s.length &amp;lt; 2 || s.length &amp;lt; numRows){
        return s
    }

    const rows = new Array(numRows).fill('')
    let count = 0
    let reverse = false;

    for (let i = 0; i &amp;lt; s.length; i++) {
        let current = s[i]
        rows[count] += current
        console.log(rows)
        reverse ? count-- : count++
        if (count === 0 || count === numRows - 1) {
            reverse = !reverse
        }
    }
   let joined = rows.join('')
   console.log(joined)
};

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

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Median of Two Sorted Arrays</title>
      <dc:creator>Seth</dc:creator>
      <pubDate>Tue, 08 Mar 2022 17:42:28 +0000</pubDate>
      <link>https://dev.to/seth_king/median-of-two-sorted-arrays-3b1i</link>
      <guid>https://dev.to/seth_king/median-of-two-sorted-arrays-3b1i</guid>
      <description>&lt;p&gt;This question is deemed "Hard", but it's not too bad at all.&lt;/p&gt;

&lt;p&gt;Let's assume we've got two parameters in our function, each are an array of nums.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
function medianTwoArrays(num1, nums2) {

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

&lt;/div&gt;



&lt;p&gt;The first thing we can do is concat them together, and then sort the newly created array from lowest to highest.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function medianTwoArrays(num1, nums2) {
  let newArray = nums1.concat(nums2)
  let sorted = newArray.sort((a,b) =&amp;gt; a - b)
}

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

&lt;/div&gt;



&lt;p&gt;Cool. We've now got a sorted merged array. Now to determine whether we have an odd or even amount of elements in our array. &lt;/p&gt;

&lt;p&gt;If the length of the new array is even, we will take the two numbers separating the lower and upper half of the array, add them together, and divide them by two. &lt;/p&gt;

&lt;p&gt;Doing so is simple. If the length modulo 2 is 0, then its even. If it has a remainder of 1, then it's odd. When its odd, we want to divide the length by 2 and the remove .5 from the index. &lt;/p&gt;

&lt;p&gt;For example, if we have 5 elements, and we want the third, we can do 5 divided by 2 which is 2.5 and minus .5 we have 2 (which is the index, so we're talking about the third element).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function medianTwoArrays(num1, nums2) {
  let newArray = nums1.concat(nums2)
  let sorted = newArray.sort((a,b) =&amp;gt; a - b)

  if (sorted.length % 2 === 1) {
    return sorted[(sorted.length/2) -.5]
  } 
    else {

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

&lt;/div&gt;



&lt;p&gt;Now lets focus on the other part of the problem, if we have 8 numbers, or 4 numbers, in the array. &lt;/p&gt;

&lt;p&gt;To solve this we will want to get the number in the lower boundary, and the number in the upper boundary, then we will divide both by 2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function medianTwoArrays(num1, nums2) {
  let newArray = nums1.concat(nums2)
  let sorted = newArray.sort((a,b) =&amp;gt; a - b)

  if (sorted.length % 2 === 1) {
    return sorted[(sorted.length/2) -.5]
  } 
    else {
 return (sorted[sorted.length/2] + sorted[sorted.length/2 -1]) /2
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And voila. We've managed to return the median whether the length of the merged and sorted array is odd or even. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>career</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Longest Substring without repeating characters</title>
      <dc:creator>Seth</dc:creator>
      <pubDate>Tue, 08 Mar 2022 15:53:43 +0000</pubDate>
      <link>https://dev.to/seth_king/longest-substring-without-repeating-characters-27dc</link>
      <guid>https://dev.to/seth_king/longest-substring-without-repeating-characters-27dc</guid>
      <description>&lt;p&gt;For this problem we are going to utilize the sliding window technique. Using this technique, we will have two pointers, and if the substring has no duplicates, we can increase the window by 1. &lt;/p&gt;

&lt;p&gt;To determine if we don't have any duplicates we will use Set.&lt;/p&gt;

&lt;p&gt;As we are traversing the string, we need to add the current letter to our set, and if we try to add it again, it won't work (this is how Sets work, they only have unique characters/elements).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function findLongestSubString(s) {
 let newSet = new Set()
 let pointerOne = 0
 let pointerTwo = 0
 let longSub = 0

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

&lt;/div&gt;



&lt;p&gt;All we've done in the above is create a new set (sets don't allow duplicates) and we've created two pointers that we will use to traverse the string. We've also created a longSub variable set to 0 since we are going to need to update this as we compare substrings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function findLongestSubString(s) {
 let newSet = new Set()
 let pointerOne = 0
 let pointerTwo = 0
 let longSub = 0 

 while (pointerOne &amp;lt; s.length) {

 }

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

&lt;/div&gt;



&lt;p&gt;In the next step above, we've said while the pointer is less then the length of the string traverse the string. Then we will say that if the set doesn't have the character that pointerOne is on, then we want to add it to the set.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
function findLongestSubString(s) {
 let newSet = new Set()
 let pointerOne = 0
 let pointerTwo = 0
 let longSub = 0 

 while (pointerOne &amp;lt; s.length) {
  if (!newSet.has(s.charAt(pointerOne))) {
   newSet.add(s.charAt[pointerOne])
  }
 }

}

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

&lt;/div&gt;



&lt;p&gt;Again, looking at what we have above, if the set doesn't have the character at the position of pointerOne, then add it to the set. &lt;/p&gt;

&lt;p&gt;We will then use Math.max, which compares two elements, to see which has the longest length and we will then set that to the maxLength.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function findLongestSubString(s) {
 let newSet = new Set()
 let pointerOne = 0
 let pointerTwo = 0
 let longSub = 0 

 while (pointerOne &amp;lt; s.length) {
  if (!newSet.has(s.charAt(pointerOne))) {
   newSet.add(s.charAt[pointerOne])
   longSub = Math.max(longSub, newSet.size)
  }
 }

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

&lt;/div&gt;



&lt;p&gt;Now, what we need to do is move pointerOne forward, we can do so by just saying pointerOne++.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function findLongestSubString(s) {
 let newSet = new Set()
 let pointerOne = 0
 let pointerTwo = 0
 let longSub = 0 

 while (pointerOne &amp;lt; s.length) {
  if (!newSet.has(s.charAt(pointerOne))) {
   newSet.add(s.charAt[pointerOne])
   longSub = Math.max(longSub, newSet.size)
   pointerOne++
  }
 }

}

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

&lt;/div&gt;



&lt;p&gt;Now this will take us through the letters in the string, but at some point we will hit a duplicate. In this case, we want to remove the current letter that pointerTwo is on (the first character in the substring).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function findLongestSubString(s) {
 let newSet = new Set()
 let pointerOne = 0
 let pointerTwo = 0
 let longSub = 0 

 while (pointerOne &amp;lt; s.length) {
  if (!newSet.has(s.charAt(pointerOne))) {
   newSet.add(s.charAt[pointerOne])
   longSub = Math.max(longSub, newSet.size)
   pointerOne++
  }
   else {
    newSet.delete(s.charAt[pointerTwo])
    pointerTwo++
    }
 }
 return longSub
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Eventually we we will get to a blank space (the end of the sting), and that means we've gone through everything. So, we can just return the longSub which is going to be a number. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>career</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Two Sum Problem</title>
      <dc:creator>Seth</dc:creator>
      <pubDate>Wed, 02 Mar 2022 03:19:21 +0000</pubDate>
      <link>https://dev.to/seth_king/two-sum-problem-992</link>
      <guid>https://dev.to/seth_king/two-sum-problem-992</guid>
      <description>&lt;p&gt;You want to find 2 numbers that add up to the target and return their indices.&lt;/p&gt;

&lt;p&gt;This is considered an easy interview problem, if you get it, god is watching over you.&lt;/p&gt;

&lt;p&gt;Now, there are few ways to approach this: the brute force way (it'l work but it aint impressive), and then the optimal way. We will cover both.&lt;/p&gt;

&lt;h2&gt;
  
  
  The brute force way
&lt;/h2&gt;

&lt;p&gt;Note: This will work, but make sure you can optimize it too.&lt;/p&gt;

&lt;p&gt;The logic is as follows. We will use two for loops. The first will look through all the elements starting at the first element. Then next loop will go through all the elements starting at second element. If the two add up to the target, return the indicies of them. Relatively straightforward, but it takes up a lot of memory to run two for loops so it'l become more inefficient as the array grows. Nevertheless, here's the answer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`var twoSum = function(nums, target) {
    let result = []
    for (let i = 0; i &amp;lt; nums.length; i++) {
    for (let j = i + 1; j &amp;lt; nums.length; j++) {
        if (nums[i] + nums[j] === target) {
            result.push(i, j)
        }
     }
   }
     return result
}`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The efficient way
&lt;/h2&gt;

&lt;p&gt;We don't want to use 2 for loops. Let's just use one. &lt;/p&gt;

&lt;p&gt;What we'll do is create an empty object, and then we'll use forEach on the nums array. The forEach method can take in an element and its index, so we can set each set the element as the key and its index as its value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
`var twoSum = function(nums, target) {
 let obj = {}
 nums.forEach((num, index) =&amp;gt; {
  obj[num] = index
 }


}`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are going to loop through the nums array and use our one shot at a for loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var twoSum = function(nums, target) {
 let obj = {}
 nums.forEach((num, index) =&amp;gt; {
  obj[num] = index
 }

 for (let i = 0; i &amp;lt; nums.length; i++) {
 let secondElement = target - element
 if (obj[secondElement] !== undefined &amp;amp;&amp;amp; obj[secondElement] !== index) {
  return [index, secondElement]
  }
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets take a look at the example above. &lt;/p&gt;

&lt;p&gt;We're looping through the numbers in the nums array and were saying, does the result of the target number minus the current element exist as a number here? That is, if the target is 9 and our nums array is [2, 7, 13, 15], does 9 - 2 exist? or does 9 - 7 exist? And is it not an existing element (we can use the same number twice)? &lt;/p&gt;

&lt;p&gt;If so, return the element, and then the secondElement i.e the result of the target element minus the current element. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>career</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>How to build Airbnb Header and Banner</title>
      <dc:creator>Seth</dc:creator>
      <pubDate>Wed, 09 Feb 2022 22:47:31 +0000</pubDate>
      <link>https://dev.to/seth_king/how-to-build-airbnb-front-end-4kbc</link>
      <guid>https://dev.to/seth_king/how-to-build-airbnb-front-end-4kbc</guid>
      <description>&lt;p&gt;Today we're going to take a look at React JS, a popular Javascript library. Before getting started with React, you should feel comfortable with Javascript. &lt;/p&gt;

&lt;p&gt;If you didn't master Javascript, it's possible you'll still learn React just fine. But in my opinion, and I'm not the end all be all on the topic by any means, it's much easier to understand how to use React when your already familiar, and hopefully proficient, in JavaScript, CSS, and HTML.&lt;/p&gt;




&lt;h2&gt;
  
  
  Download Node.js
&lt;/h2&gt;

&lt;p&gt;To check you've got node installed type in &lt;strong&gt;node -v&lt;/strong&gt; into your terminal. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ok6ieBVE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d7peadwh14npry7n3i3l.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ok6ieBVE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d7peadwh14npry7n3i3l.gif" alt="Image description" width="880" height="653"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should your version appear. If not, download Node &lt;a href="https://nodejs.org/en/download/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Next we are going to go ahead and get React downloaded.&lt;/p&gt;

&lt;p&gt;Type in: &lt;code&gt;npx create-react-app&lt;/code&gt;and then name your folder.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w6PavGYC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/487rr2gs2s5x6pcvvp58.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w6PavGYC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/487rr2gs2s5x6pcvvp58.gif" alt="Image description" width="880" height="660"&gt;&lt;/a&gt; I'll call ours &lt;strong&gt;new-app&lt;/strong&gt; so the full line of code will be:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx create-react-app my-app&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Npx stands for &lt;strong&gt;node package execute&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You'll see several dependencies start to load and you'll have 4 scripts you can run. The first one you'll want to try is npm start which will run the react app on your local machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run npm-start
&lt;/h2&gt;

&lt;p&gt;To do this, make sure you first change directory to the app folder you just created. Then run npm start. You'll see this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1mblPlgC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k8hu73wui5mx6yjh7you.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1mblPlgC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k8hu73wui5mx6yjh7you.gif" alt="Image description" width="826" height="678"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Set up Firebase
&lt;/h2&gt;

&lt;p&gt;Now you'll want to set up a Firebase server so you can see what you create and actually share it with people. Firebase will let you create the project as long as you have a Gmail account and firebase is a suite of free tools. Don't worry too much about the initial setup.&lt;/p&gt;

&lt;p&gt;When your done, register your app:&lt;/p&gt;

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

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

&lt;h2&gt;
  
  
  Delete Test Files
&lt;/h2&gt;

&lt;p&gt;You won't need all the files that you've downloaded with &lt;code&gt;npx create-react-app&lt;/code&gt;. So, we'll go ahead and delete the files related to testing.&lt;/p&gt;

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

&lt;p&gt;Also, delete the images in your "public" folder. We won't need them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Remove information in the App.js div
&lt;/h2&gt;

&lt;p&gt;Since you've deleted the images in the "public" folder, the app will present you with an error. Delete the image file from the top, and as well as the information between the divs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MbbbsyHB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/59hof9i7aiha3lud4rin.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MbbbsyHB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/59hof9i7aiha3lud4rin.png" alt="Image description" width="880" height="638"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add an H1 tag in the div and include some information here, nothing crazy. When you reload the page you'll see something like this: &lt;/p&gt;

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

&lt;p&gt;As you might be able to tell, the text is centered and there is margins to the left and right of it.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Delete everything in App.css
&lt;/h2&gt;

&lt;p&gt;This will left-align your text.&lt;/p&gt;

&lt;p&gt;Go into your &lt;strong&gt;index.css&lt;/strong&gt; and we will remove the margin everywhere using &lt;code&gt;*&lt;/code&gt; which tells the CSS to apply the changes to the entire code.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Begin building your application
&lt;/h2&gt;

&lt;p&gt;You'll want to begin by planning out the components of your application. So let's start with the &lt;strong&gt;Home&lt;/strong&gt; component. Inside of this component are several other components: &lt;strong&gt;Header, Banner, Cards, Footer&lt;/strong&gt;. Laying it out like this will help out as we go to fill out this information.&lt;/p&gt;

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

&lt;p&gt;Each of these components will be their own Javascript file inside your &lt;strong&gt;SRC&lt;/strong&gt; folder. &lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the Home component
&lt;/h2&gt;

&lt;p&gt;If you don't have it yet, download the ES7 extensions from VS Code. Then type in &lt;code&gt;rfce&lt;/code&gt; which will get you started.&lt;/p&gt;

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

&lt;p&gt;We will also create a &lt;strong&gt;Home.css&lt;/strong&gt; file so we can style the Home component. Then import it to your Home.js file. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cCOd-62m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bjlfsmge2n5e4q3y4nai.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cCOd-62m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bjlfsmge2n5e4q3y4nai.png" alt="Image description" width="880" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Re-useable Header
&lt;/h2&gt;

&lt;p&gt;Airbnb's header appears on every page that displays. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wEXzShlm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hb84qk8ffwf796sl702a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wEXzShlm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hb84qk8ffwf796sl702a.png" alt="Image description" width="880" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So let's go ahead and create the Header component i.e &lt;strong&gt;Header.js&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;At the top, import &lt;strong&gt;Header.css&lt;/strong&gt; so we can change the styling for the header and utilize it.&lt;/p&gt;

&lt;p&gt;In the Header.js file, set the div className to 'header'. &lt;/p&gt;

&lt;p&gt;Inside the div, create an &lt;code&gt;img&lt;/code&gt; element and set the className to 'header__icon' so we know it's an icon in the header. Give it an src tag with the url of the logo. The alt tag can be left blank (or fill it it in).&lt;/p&gt;

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

&lt;p&gt;The import the Header.js file to App.js to add the component in. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bl7Dq1Tm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qmxram5ht5vys99uskev.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bl7Dq1Tm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qmxram5ht5vys99uskev.png" alt="Image description" width="880" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should now see a massive logo above the Home component in your local host.  I couldn't even see it on my page it was so large.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D8FiYcE3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qdphshbfunstvb1pbebc.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D8FiYcE3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qdphshbfunstvb1pbebc.gif" alt="Image description" width="880" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To fix this, we will target the header icon in the Header.css file and give it the below properties:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;object-fit: contain;&lt;br&gt;
 height: 100px;&lt;br&gt;
 margin-left: 20px;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;object-fit&lt;/code&gt; will keep the image within the screen, and we're using &lt;code&gt;margin-left&lt;/code&gt; 20px to push it off the left border a bit.&lt;/p&gt;

&lt;p&gt;Here's what it looks like now.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Understanding the Header
&lt;/h2&gt;

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

&lt;p&gt;When we look at this more closely we can see the Header split into 3 parent container with 1-4 children. &lt;/p&gt;

&lt;p&gt;The first container &lt;strong&gt;(1)&lt;/strong&gt; just has 1 child - the image. The second &lt;strong&gt;(2)&lt;/strong&gt; has two: search and it's icon. The third &lt;strong&gt;(3)&lt;/strong&gt; has four, three icons and one text element.  &lt;/p&gt;

&lt;p&gt;Adding the property &lt;code&gt;Flex 1&lt;/code&gt; to the 2nd element will allow it to grow when we click on it and select a date.&lt;/p&gt;

&lt;p&gt;Giving the entire Header &lt;code&gt;align-items: center&lt;/code&gt; will make sure everything looks good. Every container will need these rules. &lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the search bar component
&lt;/h2&gt;

&lt;p&gt;Create a 2nd div under the header_&lt;strong&gt;icon div. Give it a className of header&lt;/strong&gt;center and an input with a type text. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FGDJU-jl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nduxwj4vd9zkw8t1dwjj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FGDJU-jl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nduxwj4vd9zkw8t1dwjj.png" alt="Image description" width="880" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we will utilize &lt;a href="https://mui.com/"&gt;Material UI&lt;/a&gt; to get the search icon. Following their documentation we will type in &lt;code&gt;$ npm install @material-ui/core&lt;/code&gt;. Then search through this &lt;a href="https://v4.mui.com/components/material-icons/"&gt;lit of icons&lt;/a&gt; to find the one matching Airbnb.&lt;/p&gt;

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

&lt;p&gt;When you find an icon you want, click on it and it'l give you the code to import at the top of your JS file.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; it's import you remember to use &lt;code&gt;npm install --save @material-ui/icons&lt;/code&gt; otherwise your going to wonder why you it's not working which happened to me and left me screwed for at least an hour. You also need to CD into your project file folder before the npm install, otherwise its worthless.&lt;/p&gt;

&lt;p&gt;Next, create a div with the className of header___right as this will be the icons and "Become a Host" section of their site.&lt;/p&gt;

&lt;p&gt;Once you've added the search icon, go ahead and add 2 more: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;ExpandMoreIcon /&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;Language /&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Then add a component of Avatar which is available through the Material UI core package.&lt;/p&gt;

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

&lt;p&gt;Now jump into the Header.css folder since we'll want to &lt;code&gt;align-items:center&lt;/code&gt; everything and make sure it has a &lt;code&gt;display:flex&lt;/code&gt; so it's in a row.&lt;/p&gt;

&lt;p&gt;Then it should be looking like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GC3MOPuA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9x01wu0lhp2jjlud2m9b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GC3MOPuA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9x01wu0lhp2jjlud2m9b.png" alt="Image description" width="880" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we then add &lt;code&gt;justify-content:space-between&lt;/code&gt; it will push all these containers the farthest space away from each other. &lt;/p&gt;

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

&lt;p&gt;Since we want to the header to stay throughout the page, even when scrolling we'll need to add the tags below to the header container.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;position: sticky;&lt;br&gt;
top: 0;&lt;br&gt;
background-color: white;&lt;br&gt;
z-index: 100;&lt;br&gt;
width: 100%;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tweaking the Header component
&lt;/h2&gt;

&lt;p&gt;The Header will need to styled with lots of specific tags, and we will refrain from going into each of them now for the sake of time. However, note that in the header___center container you'll want to add &lt;code&gt;max-width: fit-content&lt;/code&gt;. This will constrain your search field to the middle of the header.&lt;/p&gt;

&lt;p&gt;To wrap an oval around it with a border:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;border-radius: 999px;&lt;br&gt;
border: 1px solid blue;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qxGTe_vj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1i9hdm6nsb8m5bah5k2z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qxGTe_vj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1i9hdm6nsb8m5bah5k2z.png" alt="Image description" width="880" height="111"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Keep playing around with the CSS for the Header.js folder, but besides &lt;code&gt;position:sticky&lt;/code&gt; it should be straightforward. You'll be aiming for the header to look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sePo-VQU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dfojysham7rb28nk2bhy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sePo-VQU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dfojysham7rb28nk2bhy.gif" alt="Image description" width="880" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Building the Home Component
&lt;/h2&gt;

&lt;p&gt;All we've done is create a Home.js file and added the component to the App.js file. In the Home.js file, add a quick &lt;code&gt;h1&lt;/code&gt; with some text to make sure it's set up properly.&lt;/p&gt;

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

&lt;p&gt;Then add a banner component then below the h1 and create the banner file. &lt;/p&gt;

&lt;p&gt;Afterwards, import the banner in to the Home js file since it'l live inside that file.&lt;/p&gt;

&lt;p&gt;Now go to the banner.css file for styling the banner and add this:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
.banner {&lt;br&gt;
    height: 50vh;&lt;br&gt;
    position: relative;&lt;br&gt;
    background: url("http://cdn.home-designing.com/wp-content/uploads/2017/10/white-sectional-sofa.jpg");&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This gives the banner a background image and sets the height to about 50% of the page.&lt;/p&gt;

&lt;p&gt;To center the image properly, add &lt;code&gt;center center&lt;/code&gt; to the end of the background tag. This is approximately what you'll see:&lt;/p&gt;

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

&lt;p&gt;Next, we'll go ahead and create a div within the banner and include some text within it (Airbnb does this, so we are too):&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div className='banner'&amp;gt;&lt;br&gt;
        &amp;lt;div className='banner__info'/&amp;gt;&lt;br&gt;
        &amp;lt;h1&amp;gt; Get ready to explore &amp;lt;/h1&amp;gt;&lt;br&gt;
        &amp;lt;h5&amp;gt; Your dreams aren't far away &amp;lt;/h5&amp;gt;&lt;br&gt;
    &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5JvfTC16--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b4imw2va3e7axmtn5io9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5JvfTC16--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b4imw2va3e7axmtn5io9.png" alt="Image description" width="880" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We've came along way. Import a button from the material UI core folder then put it in underneath the text you added. &lt;/p&gt;

&lt;p&gt;Afterwards, we're going to need to style everything to make sure it looks similar to how Airbnb has their site set up.&lt;/p&gt;

&lt;p&gt;`.banner {&lt;br&gt;
    height: 50vh;&lt;br&gt;
    position: relative;&lt;br&gt;
    background: url("&lt;a href="http://cdn.home-designing.com/wp-content/uploads/2017/10/white-sectional-sofa.jpg%22)center"&gt;http://cdn.home-designing.com/wp-content/uploads/2017/10/white-sectional-sofa.jpg")center&lt;/a&gt; center;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.banner__info {&lt;br&gt;
    background-color: black;&lt;br&gt;
    color: white;&lt;br&gt;
    padding-top: 25vh;&lt;br&gt;
    padding-left: 50px;&lt;br&gt;
    padding-right: 50px;&lt;br&gt;
    padding-bottom: 40px;&lt;br&gt;
    width: 300px;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.banner__info &amp;gt; button {&lt;br&gt;
    background-color: #ff7779;&lt;br&gt;
    color: white;&lt;br&gt;
    border: 2px solid white;&lt;br&gt;
}`&lt;/p&gt;

&lt;p&gt;For the &lt;strong&gt;banner&lt;/strong&gt;, we're setting the height to 50% of the page. The rest should be explanatory.&lt;/p&gt;

&lt;p&gt;For &lt;strong&gt;banner info&lt;/strong&gt;, we're giving it a background color of black, and the text color of white. Then we're going to give it some padding.&lt;/p&gt;

&lt;p&gt;For the &lt;strong&gt;banner button&lt;/strong&gt;, we've given it the colors to match Airbnb. And this is where we're at.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KSUgVc51--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/71m73nr97yf5rshbei4e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KSUgVc51--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/71m73nr97yf5rshbei4e.png" alt="Image description" width="880" height="362"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Banner
&lt;/h2&gt;

&lt;p&gt;Note: Anything styled with a Material UI button needs the CSS property of &lt;code&gt;!important&lt;/code&gt; to override its native CSS.&lt;/p&gt;

&lt;p&gt;Underneath the Home Component placehodler text, add a Search Dates button.&lt;/p&gt;

&lt;p&gt;Then in the Banner, create a div container with a className of 'banner__search'. &lt;/p&gt;

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

&lt;p&gt;Now, inside that div we will have a button with a classNAme of 'banner__searchButton' so we can style it later.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.banner__searchButton {&lt;br&gt;
    background-color: white !important;&lt;br&gt;
    font-weight: 900 !important;&lt;br&gt;
    text-transform: capitalize imo !important;&lt;br&gt;
    color: #ff7779;&lt;br&gt;
    width: 100vh;&lt;br&gt;
} &lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The styling above's use of !important makes sure it overrides the CSS associated with Material UI. Now when you hover over the button, you'll see it matches Airbnb's branding outline.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get the Search Dates button to span the entire column of the page
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;.banner__search{&lt;br&gt;
    flex-direction: column;&lt;br&gt;
    display: flex;&lt;br&gt;
    top: 0;&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Currently when you click on it, you get a nice animation effect since we're using the button from Material UI, which already has code associated with the button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--He5hHpnu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hcs7f6hzaxlfqfhc9gpa.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--He5hHpnu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hcs7f6hzaxlfqfhc9gpa.gif" alt="Image description" width="880" height="317"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But we'll want to change the start on it, so when its clicked, it shows the calendar. When it's not click, it stayed on this state. &lt;/p&gt;

&lt;p&gt;To do this we'll start by importing { useState } from 'react'.&lt;/p&gt;

&lt;p&gt;Then underneath the banner__search div we'll say if it's true, show the search bar component (we'll create this later). If it's false, hide it.&lt;/p&gt;

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

&lt;p&gt;To add the functionality, we'll say that the Button onClick will set setShowSearch to the opposite of showSearch.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;onClick={() =&amp;gt; setShowSearch(!showSearch)}&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the Date Range component
&lt;/h2&gt;

&lt;p&gt;Type in &lt;code&gt;npm i react-date-range&lt;/code&gt; which is a handy npm library to have around.&lt;/p&gt;

&lt;p&gt;To import it write:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
import { DateRangePicker } from 'react-date-range'&lt;br&gt;
import "react-date-range/dist/styles.css"&lt;br&gt;
import "react-date-range/dist/theme.css"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, let's write a function that will set the startDate/endDate to the selection someone would choose as they're looking over the calendar.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;function setSelection(ranges) {&lt;br&gt;
      setStartDate(ranges.selection.startDate)&lt;br&gt;
      setEndDate(ranges.selection.endDate)&lt;br&gt;
  }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is also done by the library we've set up via NPM.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to install Tailwind CSS via Visual Studio Code using NPM</title>
      <dc:creator>Seth</dc:creator>
      <pubDate>Fri, 14 Jan 2022 22:41:56 +0000</pubDate>
      <link>https://dev.to/seth_king/how-to-install-tailwind-css-via-visual-studio-code-using-npm-445a</link>
      <guid>https://dev.to/seth_king/how-to-install-tailwind-css-via-visual-studio-code-using-npm-445a</guid>
      <description>&lt;p&gt;Tailwind CSS lets you leverage utility classes to build &lt;strong&gt;your own&lt;/strong&gt; components. This means you can reference Tailwind CSS classes directly in HTML.&lt;/p&gt;

&lt;p&gt;Yup, you heard that right.  &lt;/p&gt;

&lt;p&gt;To begin, create a new folder on your desktop and open the folder in &lt;a href="https://code.visualstudio.com/"&gt;Visual Studio Code&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Get started
&lt;/h2&gt;

&lt;p&gt;If you have Visual Studio Code, pull up the terminal. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uQl9H6y_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7cpn7tvjeqzy5kic4xmm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uQl9H6y_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7cpn7tvjeqzy5kic4xmm.png" alt="Image description" width="800" height="704"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Type in &lt;strong&gt;npm -v&lt;/strong&gt;. This command is necessary to see which version of npm you are running. If you don't have it installed, you'll have an error message. &lt;em&gt;If you didn't download npm, don't worry. It's pretty easy, &lt;a href="https://nodejs.org/en/download"&gt;just search for it on Google&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now go ahead and also install node.js. To make sure it's there, run npm -v again in the terminal. If you see your version, it's running and installed properly. If not, you're out of luck. &lt;/p&gt;

&lt;p&gt;Nows our time for real trickery - type in &lt;code&gt;npm install -d tailwindcss@latest postcss@latest autoprefixer@lates&lt;/code&gt;t in your console.  &lt;/p&gt;

&lt;p&gt;You should see a lot of GET requests and 200 messages (which mean everything worked fine) roll in. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VaSCpRxm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/31zuxo7fxlwm8kv8epj2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VaSCpRxm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/31zuxo7fxlwm8kv8epj2.png" alt="Image description" width="778" height="340"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Reviewing your folders
&lt;/h2&gt;

&lt;p&gt;After installing Tailwind CSS, you should see your folder has 3 files: &lt;strong&gt;node-modules&lt;/strong&gt;, &lt;strong&gt;package-lock.json&lt;/strong&gt;, &lt;strong&gt;package.json&lt;/strong&gt;. In my case they are in the  tailwind folder that I set up. For the sake of this exercise, I pulled in a Linktree clone I was working on. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7wlTcwcx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ejng4ebflppnbwx6k4ht.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7wlTcwcx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ejng4ebflppnbwx6k4ht.png" alt="Image description" width="800" height="243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The package.json folder has the dependencies we download, as well as their file version. &lt;/p&gt;

&lt;p&gt;At this point, we will add a configuration file to the package.json file. &lt;/p&gt;




&lt;h2&gt;
  
  
  Add a configuration file to the package.json file.
&lt;/h2&gt;

&lt;p&gt;Typine in "&lt;strong&gt;npx tailwindcss init&lt;/strong&gt;" into the terminal.  It's something that has to happen eventually (or so I'm told), so it's better to get it out the way now. You'll then see a tailwind.config.js file pop up in your folder. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7bSFM0VN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1kgti5v8qjfay9ob0n1h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7bSFM0VN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1kgti5v8qjfay9ob0n1h.png" alt="Image description" width="800" height="596"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now create a style.css file in the tailwind folder (it's fine if you call it something different). In this file, we will add some Tailwind directives. Type in:&lt;/p&gt;

&lt;p&gt;&lt;a class="mentioned-user" href="https://dev.to/tailwind"&gt;@tailwind&lt;/a&gt; base;&lt;br&gt;
&lt;a class="mentioned-user" href="https://dev.to/tailwind"&gt;@tailwind&lt;/a&gt; components;&lt;br&gt;
&lt;a class="mentioned-user" href="https://dev.to/tailwind"&gt;@tailwind&lt;/a&gt; utilities;&lt;/p&gt;

&lt;p&gt;These directives are pulled from the &lt;strong&gt;node_modules &amp;gt; Tailwind CSS folders.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DELNjhHs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f148cun27irhm9yf0arf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DELNjhHs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f148cun27irhm9yf0arf.png" alt="Image description" width="800" height="648"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Switch to package.json folder
&lt;/h2&gt;

&lt;p&gt;Now add a comma and then in double quotes add:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"scripts": {&lt;br&gt;
    "build-css": "tailwindcss build style.css -o css/style.css"&lt;br&gt;
  }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It's a simple key-value pair. build-css is the key, the value is tailwindcss. Build refers to what we want to build i.e our style.css file that we got. The -o specifies the output file. The final portion &lt;strong&gt;css/style/css&lt;/strong&gt; tells the computer where we will store it.&lt;/p&gt;

&lt;p&gt;Now in the console type in the script. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run build-css&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This tells it to run the build-css key-value. &lt;/p&gt;

&lt;p&gt;You should see a new folder built with CSS file inside. I'll end our lesson here, as you've set everything up correctly. Now the fun part begins - building! &lt;/p&gt;




</description>
    </item>
    <item>
      <title>The Two Pointer Technique</title>
      <dc:creator>Seth</dc:creator>
      <pubDate>Mon, 03 Jan 2022 22:25:08 +0000</pubDate>
      <link>https://dev.to/seth_king/the-two-pointer-technique-1b62</link>
      <guid>https://dev.to/seth_king/the-two-pointer-technique-1b62</guid>
      <description>&lt;p&gt;It's possible to brute force your way into solving a problem. But doing so leads to an inefficient solution. &lt;/p&gt;

&lt;p&gt;One common inefficient, brute force method you might see in the wild is the notorious double loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function findpairs(arr, k) {
for (let i = 0; i &amp;lt; arr.length - 1; i++) {
 for (let k = 1 + 1; i &amp;lt; arr.length; k++) {
  }
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It takes forever to go through every element in an array once, but twice? Forget about it. &lt;/p&gt;

&lt;p&gt;Instead of using double loops, consider using what is affectionately known as "The Two Pointer Technique". &lt;/p&gt;




&lt;h2&gt;
  
  
  What is a pointer?
&lt;/h2&gt;

&lt;p&gt;In a for loop, the "i" value is the pointer i.e. it goes through each item in the array. &lt;/p&gt;

&lt;p&gt;But we if have 2 pointers we can make different calculations based on the different pointers. It is also much faster than using two for loops as both pointers can move through the array at the same time (don't quote me on this part though).&lt;/p&gt;

&lt;p&gt;In the example below, the carot symbol &lt;strong&gt;(^)&lt;/strong&gt; is meant to visualize the two pointer concept. The array is in ascending order, which means the first element is the minimum and the last is the max.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [ 1, 2, 3, 4, 5, 6]
              ^              ^
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While there are perhaps thousands of different combinations of pointers, the most typical combination is to have one start at the beginning, and another to start at the end. &lt;/p&gt;

&lt;p&gt;Let' see now how we can solve a simple problem using this two pointer method.&lt;/p&gt;




&lt;h2&gt;
  
  
  The situation
&lt;/h2&gt;

&lt;p&gt;We have an array that is sorted in ascending order, and we want to see if any pair of the elements in the array sum up to X.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = [1, 2, 3, 4, 5, 6, 7, 8]
                  ^                 ^
const x = 10

function findPairs(array, x) {
 let start = 0; //set the first element
 let end = array.length - 1; //set the last element

 while (start &amp;lt; end) {
  if (array[start] + array[end] === x) {
   return true; //if any two elements equal x, we are done. 
  } else if (array[start] + array[end] &amp;lt; x) {

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

&lt;/div&gt;



&lt;p&gt;In the "else if" statement runs, we will change the first pointer to the next element in the array. &lt;/p&gt;

&lt;p&gt;We will keep the second element in place, but need to increment the position (start++) of the first pointer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = [1, 2, 3, 4, 5, 6, 7, 8]
                  ^                 ^
const x = 10

function findPairs(array, x) {
 let start = 0; //set the first element
 let end = array.length - 1; //set the last element

 while (start &amp;lt; end) {
  if (array[start] + array[end] === x) {
   return true; //if any two elements equal x, we are done. 
  } else if (array[start] + array[end] &amp;lt; x) {
   start++
  }
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Don't forget your second pointer
&lt;/h2&gt;

&lt;p&gt;This situation above, however, doesn't fully satisfy all conditions. While the array is sorted, if a number is missing from the array it will result in an infinite loop. &lt;/p&gt;

&lt;p&gt;This is because once  the first pointer has made it through the loop, it will continue to look for the missing number. This search, though, is in vain. &lt;/p&gt;

&lt;p&gt;The way we will get around it is by decrementing from the last element in the array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = [1, 3, 4, 5, 6, 7, 8]
                  ^        ^
const x = 10

function findPairs(array, x) {
 let start = 0; //set the first element
 let end = array.length - 1; //set the last element

 while (start &amp;lt; end) {
  if (array[start] + array[end] === x) {
   return true; //if any two elements equal x, we are done. 
  } else if (array[start] + array[end] &amp;lt; x) {
   start++;
  } else {
    else--;
   }
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Return index of the elements
&lt;/h2&gt;

&lt;p&gt;This might seem tricky since there are lots of combinations of elements that can equal the sum of X, but all we need to do is return the &lt;strong&gt;start&lt;/strong&gt; and &lt;strong&gt;end&lt;/strong&gt; instead of returning &lt;strong&gt;true&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = [1, 3, 4, 5, 6, 7, 8]
                  ^        ^
const x = 10

function findPairs(array, x) {
 let start = 0; //set the first element
 let end = array.length - 1; //set the last element

 while (start &amp;lt; end) {
  if (array[start] + array[end] === x) {
   **return [start, end]**; //if any two elements equal x, we are done. 
  } else if (array[start] + array[end] &amp;lt; x) {
   start++;
  } else {
    else--;
   }
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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