<?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: Henry Cook</title>
    <description>The latest articles on DEV Community by Henry Cook (@henrycook).</description>
    <link>https://dev.to/henrycook</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%2F443616%2F9beb2a88-0399-40d8-920f-62b3fb243d8a.png</url>
      <title>DEV Community: Henry Cook</title>
      <link>https://dev.to/henrycook</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/henrycook"/>
    <language>en</language>
    <item>
      <title>Takeaways from my first group project. </title>
      <dc:creator>Henry Cook</dc:creator>
      <pubDate>Sun, 30 Aug 2020 16:29:55 +0000</pubDate>
      <link>https://dev.to/henrycook/takeaways-from-my-first-group-project-5cel</link>
      <guid>https://dev.to/henrycook/takeaways-from-my-first-group-project-5cel</guid>
      <description>&lt;p&gt;I just finished my first group project! I am used to building things on my own, so this was a completely different adventure. Here are four things I learned: &lt;/p&gt;



&lt;h2&gt;
  
  
  1. Planning the order in which components are built is critical.
&lt;/h2&gt;

&lt;p&gt;I'm sorry experienced people, I know this is super basic. However, this wasn't immediately clear. When working alone it's pretty easy to say "Oh yeah, I need that thing, let me build it real quick". When working in a group I realized that you need to plan for those "extra" things ahead of time. The front end of our project was built in React, so we needed to make sure that all of the routes were completed. This allows everyone to test their components while they build them. Sure, maybe it would only take 5 minutes for someone to build out our app.js, but having it completed before divvying up tasks is much more efficient. The amount of "extra" things can build-up, and cause a lot of wasted time. &lt;/p&gt;

&lt;p&gt;Also, this generally makes things easier to debug. Personally I have sat looking at the screen scratching my head wondering why I can't make an API call, only to then realize that I never even built the API config file. &lt;/p&gt;

&lt;p&gt;Here is my advice to anyone relatively new (like me), before building any project you should sit down and write out a plan. It sounds so basic, but it is so important. Trust me, we had a much better and more efficient experience once there was a plan in place. I would recommend GitHub projects to help with this, it's pretty easy to get the hang of and it streamlines the whole process (I would love to hear people's alternatives).&lt;/p&gt;

&lt;h2&gt;
  
  
  2. The nice thing about building something with other people is that the work is split up!
&lt;/h2&gt;

&lt;p&gt;There isn't any advice here, It's just super nice to not have to build everything yourself. I am a detail person, so I liked being able to focus on each of my tasks down to the smallest feature. This allowed me to produce higher quality components. &lt;/p&gt;

&lt;p&gt;Also, our team met on zoom anytime we would merge our branches together. I loved merging everything and then seeing all of the new pieces fitting in and working together. It felt like we were progressing in giant leaps, rather than monotonously chipping away at some behemoth. &lt;/p&gt;

&lt;h2&gt;
  
  
  3. Pair Programming is great.
&lt;/h2&gt;

&lt;p&gt;Pair programming helped us tremendously. This honestly made our team 10x more efficient. We pair programmed by having one person share their screen and one person watch (I don't actually know how people do it professionally, maybe like this? let me know.) This dramatically reduced my pretty routine spelling and syntax errors. It was also really cool to plan out the logical steps for any solution with someone else. &lt;/p&gt;

&lt;p&gt;Another reason I liked pair programming, is that it was fun! This isn't a very professional reason, but it was. I had a good time working with someone else and creating something together. &lt;/p&gt;

&lt;p&gt;Sometimes learning to write code can be a pretty solitary thing. My partner and friends have very little interest in listening to me describe anything I'm working on. Pair programming allowed me to work with someone who is passionate about the same things. &lt;/p&gt;

&lt;h2&gt;
  
  
  4. Communication is probably one of the most important parts of group work.
&lt;/h2&gt;

&lt;p&gt;This is a big topic, I've listed a few examples: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Actually listening to people when you ask for help. &lt;/li&gt;
&lt;li&gt;Taking everyone's opinions into consideration.&lt;/li&gt;
&lt;li&gt;Monitoring your ego to ensure that you aren't deluding yourself into thinking you know what's best.&lt;/li&gt;
&lt;li&gt;Keeping calm during a disagreement and looking for a diplomatic solution. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I could write a whole blog post about ways to improve your communication skills (oh wait, &lt;a href="https://medium.com/@henryfcook3/thinking-on-your-feet-and-dealing-with-ego-6a673704a862"&gt;I did!&lt;/a&gt;) so I won't go into a lot of detail. I think it is important to mention that a lot of the disagreements that can crop up in a team environment are "I'm the one who is correct" power struggles. Things like this are not conducive to progress. My advice here is to listen to everyone, recognize that you may be wrong and that is not a reflection of your intelligence, and learn to trust your teammates. &lt;/p&gt;




&lt;p&gt;I love building things by myself, I can listen to loud music and disappear into the code. I was nervous when I started this project, and I didn't know what to expect. However, it actually turned out great! My biggest takeaway is that group projects can be quite enjoyable and collaboration can help you build bigger and better things. &lt;/p&gt;

</description>
      <category>beginners</category>
    </item>
    <item>
      <title>Another Post on Bubble Sort</title>
      <dc:creator>Henry Cook</dc:creator>
      <pubDate>Sat, 01 Aug 2020 22:45:36 +0000</pubDate>
      <link>https://dev.to/henrycook/another-post-on-bubble-sort-2cce</link>
      <guid>https://dev.to/henrycook/another-post-on-bubble-sort-2cce</guid>
      <description>&lt;p&gt;Let's talk about bubble sort, again. Well, okay, for some of you it's again, but I'm new around these parts. Why am I talking about an algorithm that's used very little outside of the classroom? Because spending time with it, regardless of efficiency has helped me chip away at the barriers between logical thinking and my brain. &lt;/p&gt;

&lt;p&gt;What is Bubble sort?&lt;/p&gt;

&lt;p&gt;Bubble sort is a sorting algorithm. It loops through an array and the largest values will "bubble" to the end until its completely sorted. If you dislike this term, you are not alone. I am a visual person and placing elements towards the end of an array doesn't give the appearance of bubbling up. Unfortunately, the "Placing elements towards the end of the array as they get sorted sort" isn't as catchy. &lt;/p&gt;

&lt;p&gt;Let's jump into it. Here is the basic premise of Bubble sort: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Our input is an unsorted array. &lt;/li&gt;
&lt;li&gt;We loop through the array comparing the first element to the second. &lt;/li&gt;
&lt;li&gt;If it is larger than the second element we swap them.&lt;/li&gt;
&lt;li&gt;Repeat until the array is sorted. &lt;/li&gt;
&lt;li&gt;That's it. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The keystone of this algorithm is the swap. You can write this as a function, or just throw that puppy in there. &lt;/p&gt;

&lt;p&gt;Here are two different ways to write a swap function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//The OG: 

function swap(arr, i, j) {
let temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}

//The ES6 version:

const swap = (arr, i, j) =&amp;gt; {
[arr[i], arr[j]] = [arr[j], arr[i]]
}

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



&lt;p&gt;The first one, in my opinion, is more readable so I will stick to using that. However, I will include a solution at the bottom that includes the second. &lt;/p&gt;

&lt;p&gt;In the first swap function, you can see that we set a temporary variable &lt;code&gt;let temp = arr[i];&lt;/code&gt; This allows us to store the element at &lt;code&gt;arr[i]&lt;/code&gt; so we do not lose its value. Then we set &lt;code&gt;arr[i]&lt;/code&gt; to equal &lt;code&gt;arr[j]&lt;/code&gt; and finally set arr[j] to temp. It's pretty straight forward, but the first time I tried to solve this it took me a second to think of adding a third variable. It's important to mention that people with experience would add a third variable without much thought, but if you are coming from a place that doesn't include much logical thinking(ahem, me) something small like this can be difficult.  &lt;/p&gt;

&lt;p&gt;The next step in creating this algorithm is to add a nested for loop. Usually we want to avoid this kind of thing, but with Bubble sort, we need it. I am going to start with the version of Bubble sort that is not optimized. Trust me, it's better to start this way and then step through the logic of optimization. &lt;/p&gt;

&lt;p&gt;Here is the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function bubbleSort(arr) {
  for (let i = 0; i &amp;lt; arr.length; i++) {
    for (let j = 0; j &amp;lt; arr.length; j++) {
      if (arr[j] &amp;gt; arr[j + 1]) {
        let temp = arr[j + 1];
        arr[j + 1] = arr[j];
        arr[j] = temp;
      }
    }
  }

  return arr;
}

bubbleSort([4,7,2,1,7,5,9])

 =&amp;gt; [1, 2, 4, 5, 7, 7, 9]

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



&lt;p&gt;Please note that I did not use a swap function, as mentioned above, I just threw that puppy in there. &lt;/p&gt;

&lt;p&gt;The first loop will start from the first element in the array and continue towards the end. The inner loop does the same. Within the inner loop is a conditional that checks if the targeted element is greater than the one to the right &lt;code&gt;if (arr[j] &amp;gt; arr[j + 1])&lt;/code&gt;, If it is greater then they swap! This happens until the array is completely sorted. Woohoo! &lt;/p&gt;

&lt;p&gt;Unfortunately, this method is even more inefficient than bubble sort already is. Add a console.log right after the second for loop and you would see two things, the first being that we are comparing elements that have already been sorted, and second, being we are comparing the last element to an undefined element.  &lt;/p&gt;

&lt;p&gt;Example showing elements being compared:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;4 7
7 2
7 1
7 7
7 5
7 9
9 undefined
4 2
4 1
4 7
7 5
7 7
7 9
9 undefined
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To address this problem we set the first for loop to count down the array. Then we set the second for loop to run until the last element that was added to the sorted part of the array. Remember that we are placing elements(bubbling them) towards the end of the array. &lt;/p&gt;

&lt;p&gt;It looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function bubbleSort(arr) {

    for(let i = arr.length - 1; i &amp;gt; 0; i-- ) {
        for( let j = 0; j &amp;lt; i - 1; j++) {
            if(arr[j] &amp;gt; arr[j+1]) {
              let temp = arr[j+1];
                arr[j+1] = arr[j];
                arr[j] = temp;
            }    
        }
    }

    return arr;
}

bubbleSort([4,7,2,1,7,5,9])

 =&amp;gt; [1, 2, 4, 5, 7, 7, 9]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This makes sure that the inner loop doesn't include any of the elements that have been sorted. &lt;/p&gt;

&lt;p&gt;Almost there. We can optimize Bubble sort even further. There is still one issue that we haven't talked about. If the array is nearly sorted at the beginning of the function(like this: &lt;code&gt;[1,2,3,4,6,5]&lt;/code&gt;) our for loops will not stop looping until their conditions are met. So we have to add some logic in to stop the process when the arr is completely sorted. &lt;/p&gt;

&lt;p&gt;Here you go:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function bubbleSort(arr) {
  let didNotSwap;
  for (let i = arr.length - 1; i &amp;gt; 0; i--) {
   didNotSwap = true;
    for (let j = 0; j &amp;lt; i - 1; j++) {
      if (arr[j] &amp;gt; arr[j + 1]) {
        let temp = arr[j + 1];
        arr[j + 1] = arr[j];
        arr[j] = temp;
        didNotSwap = false;
      }
    }
    if (didNotSwap) break;
  }

  return arr;
}

bubbleSort([4, 7, 2, 1, 7, 5, 9]);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you can tell we introduced a variable &lt;code&gt;let didNotSwap;&lt;/code&gt;. In the first loop, we set this to true. Then after the if statement in the second loop we set it to false. The last piece we added was &lt;code&gt;if (didNotSwap) break;&lt;/code&gt;. If there was not a swap then we break out of the loop and return the newly sorted array. &lt;/p&gt;

&lt;p&gt;All done! While Bubble sort is not a very efficient algorithm,  It does help add to the foundation of logical thinking.&lt;/p&gt;

&lt;p&gt;Thank you so much for reading this! &lt;/p&gt;

&lt;p&gt;Also here is the extra solution as promised:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function bubbleSort(arr) {
  let didNotSwap;
  for (let i = arr.length - 1; i &amp;gt; 0; i--) {
    didNotSwap = true;
    for (let j = 0; j &amp;lt; i - 1; j++) {
      if (arr[j] &amp;gt; arr[j + 1]) {
        [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
        didNotSwap = false;
      }
    }
    if (didNotSwap) break;
  }

  return arr;
}

bubbleSort([4, 7, 2, 1, 7, 5, 9]);

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



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