<?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: Claire Muller</title>
    <description>The latest articles on DEV Community by Claire Muller (@clairemuller).</description>
    <link>https://dev.to/clairemuller</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%2F145658%2F71b27141-0c44-410e-ad91-925f92579a82.jpeg</url>
      <title>DEV Community: Claire Muller</title>
      <link>https://dev.to/clairemuller</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/clairemuller"/>
    <language>en</language>
    <item>
      <title>4 Job Search Tips</title>
      <dc:creator>Claire Muller</dc:creator>
      <pubDate>Sun, 01 Sep 2019 23:16:19 +0000</pubDate>
      <link>https://dev.to/clairemuller/4-job-search-tips-138c</link>
      <guid>https://dev.to/clairemuller/4-job-search-tips-138c</guid>
      <description>&lt;p&gt;Happy Labor Day Weekend! This week I thought I would gather up some of my favorite tips when it comes to looking for a job in the webdev / software engineering world.&lt;/p&gt;

&lt;h2&gt;
  
  
  network
&lt;/h2&gt;

&lt;p&gt;The first tip that I hear all the time is to just put yourself out there! Go to meetups and events where you can meet people who are doing what you want to be doing. I've met so many people and gotten great leads on jobs just by going to a meetup or two a week.&lt;/p&gt;

&lt;p&gt;It can feel a bit awkward at first, but I always try to get someone's contact information, usually by connecting on LinkedIn. Doing this allows you to keep the lines of communication open, and they'll be much more likely to think of you when they have an opportunity.&lt;/p&gt;

&lt;h2&gt;
  
  
  have an online presence
&lt;/h2&gt;

&lt;p&gt;When applying for jobs, I feel like it's very important to have a good presence online. Writing a weekly blog is a great way to get your name out there and employers love to see that you're engaged in the community. Similarly, &lt;a href="https://twitter.com" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; has become a wonderful place to interact with other devs and get advice from people all over the world.&lt;/p&gt;

&lt;p&gt;Check out my previous blog post about perfecting your online presence!&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/clairemuller" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F145658%2F71b27141-0c44-410e-ad91-925f92579a82.jpeg" alt="clairemuller"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/clairemuller/tips-for-perfecting-your-online-presence-1cjd" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Tips for Perfecting Your Online Presence&lt;/h2&gt;
      &lt;h3&gt;Claire Muller ・ May 13 '19&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#career&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  follow up
&lt;/h2&gt;

&lt;p&gt;The hardest part about looking for a job is when you don't hear back about a job application or connection. But I've learned to embrace the awkward and just follow up! People are busy, and we all get so many emails that it can be easy to miss things.&lt;/p&gt;

&lt;p&gt;Following up can lead to opportunities! Sending a kind 'great to meet you' message will remind them of who you are and the (hopefully) great conversation you had. People love to be thought of and in turn will think of you.&lt;/p&gt;

&lt;h2&gt;
  
  
  code every day
&lt;/h2&gt;

&lt;p&gt;My final tip is to work on some code every single day. It's easy to get overwhelmed with all the other aspects of the job search, and forget to keep working on your skills. I started the &lt;a href="https://www.100daysofcode.com/" rel="noopener noreferrer"&gt;100 Days of Code&lt;/a&gt; challenge on twitter and it's been a great way to keep myself accountable for coding a little bit each day.&lt;/p&gt;

&lt;p&gt;Don't forget to commit your changes to your GitHub, as employers definitely look! As for what to work on, I like doing &lt;a href="https://leetcode.com/" rel="noopener noreferrer"&gt;LeetCode&lt;/a&gt; problems, or here's another blog post I wrote about project ideas!&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/clairemuller" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F145658%2F71b27141-0c44-410e-ad91-925f92579a82.jpeg" alt="clairemuller"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/clairemuller/what-should-i-make-next-quick-project-ideas-5cc0" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;What Should I Make Next? Quick Project Ideas&lt;/h2&gt;
      &lt;h3&gt;Claire Muller ・ Aug 25 '19&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#projects&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#ideas&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;Thanks so much for reading and I'll see you next week!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>career</category>
      <category>tips</category>
    </item>
    <item>
      <title>What Should I Make Next? Quick Project Ideas</title>
      <dc:creator>Claire Muller</dc:creator>
      <pubDate>Sun, 25 Aug 2019 23:16:36 +0000</pubDate>
      <link>https://dev.to/clairemuller/what-should-i-make-next-quick-project-ideas-5cc0</link>
      <guid>https://dev.to/clairemuller/what-should-i-make-next-quick-project-ideas-5cc0</guid>
      <description>&lt;p&gt;Ever since I finished up at the Flatiron School at the end of May, I've been trying to come up with a cool, new project idea. But here I am, almost three months later and I haven't started one. I've been stuck in decision paralysis and it's time to break free!&lt;/p&gt;

&lt;p&gt;I've heard from a lot of people to just start something, especially when you're a junior dev. Instead of trying to reinvent the wheel, make a simple site that has some functionality. The point is to get practice and learn a new thing or two.&lt;/p&gt;

&lt;p&gt;So for my blog post this week, I'm just going to make a big list of project ideas! No longer can I complain that I don't have an idea!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;todo app (just kidding!)&lt;/li&gt;
&lt;li&gt;clone of a popular social media site&lt;/li&gt;
&lt;li&gt;site that gathers and displays news about a specific topic&lt;/li&gt;
&lt;li&gt;site to order food from a local restaurant, with a shopping cart&lt;/li&gt;
&lt;li&gt;clock that you can change from analog to digital&lt;/li&gt;
&lt;li&gt;simple chat room&lt;/li&gt;
&lt;li&gt;bill splitting app like &lt;a href="https://www.splitwise.com/"&gt;Splitwise&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;site that changes colors based on the weather&lt;/li&gt;
&lt;li&gt;funny name generator&lt;/li&gt;
&lt;li&gt;site to save and display articles you want to read later&lt;/li&gt;
&lt;li&gt;date suggestions&lt;/li&gt;
&lt;li&gt;bio site about someone famous that you like&lt;/li&gt;
&lt;li&gt;copy a simple game, like tic-tac-toe, hangman, or snake&lt;/li&gt;
&lt;li&gt;chatbot&lt;/li&gt;
&lt;li&gt;counter to log how many glasses of water you've drunk&lt;/li&gt;
&lt;li&gt;site for cute pictures of your pet&lt;/li&gt;
&lt;li&gt;simple quiz game&lt;/li&gt;
&lt;li&gt;place to keep track of all the shoes you want to buy&lt;/li&gt;
&lt;li&gt;web scraper&lt;/li&gt;
&lt;li&gt;net worth tracker&lt;/li&gt;
&lt;li&gt;calculator&lt;/li&gt;
&lt;li&gt;music suggestions based on a given song/artist&lt;/li&gt;
&lt;li&gt;site that simply tells you if it's going to rain or not&lt;/li&gt;
&lt;li&gt;spoiler alert browser extension - notifies you if the page contains certain keywords&lt;/li&gt;
&lt;li&gt;e-commerce clone&lt;/li&gt;
&lt;li&gt;a site that just plays Mariah Carey music videos&lt;/li&gt;
&lt;li&gt;word-a-day site&lt;/li&gt;
&lt;li&gt;recipe generator&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There we have it, no more excuses! I hope this inspires you to start something new today!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>projects</category>
      <category>ideas</category>
    </item>
    <item>
      <title>3 Productivity Tips</title>
      <dc:creator>Claire Muller</dc:creator>
      <pubDate>Mon, 19 Aug 2019 02:10:09 +0000</pubDate>
      <link>https://dev.to/clairemuller/3-productivity-tips-2le2</link>
      <guid>https://dev.to/clairemuller/3-productivity-tips-2le2</guid>
      <description>&lt;p&gt;Happy Sunday! I'm taking a break from the algorithms this week to write about something near and dear to my heart: productivity. As someone who's currently looking for a job, my days are wide open and thus I have to hold myself accountable for getting work done. It can feel a little overwhelming to be faced with a new day and no plan of how to fill it. So with that, my first tip:&lt;/p&gt;

&lt;h1&gt;
  
  
  schedule everything
&lt;/h1&gt;

&lt;p&gt;Like a lot of people these days, I have a virtual calendar. I use it to keep track of the many events, meetups, dinners, hikes, etc. that happen in my life. A few weeks into my job search I realized that a whole day could go by and I would wonder, 'what did I even do today?' Or I would wake up with no real plan of what I wanted to accomplish.&lt;/p&gt;

&lt;p&gt;I will say, I'm a born planner; I briefly considered becoming the next Marie Kondo. So I decided to start planning out my days ahead of time, in (possibly excessive) detail. I created a separate calendar and add blocks of time, usually 1 to 2 hours, to work on various tasks. Some examples from my own calendar include: LeetCode, clean kitchen, admin, slack bot.&lt;/p&gt;

&lt;p&gt;I'm always moving tasks around, adjusting times, and adding new ones. Now I can have a clear idea of what my day looks like, and no longer look back wondering what I even accomplished. Productivity win!&lt;/p&gt;

&lt;h1&gt;
  
  
  take breaks
&lt;/h1&gt;

&lt;p&gt;As I schedule everything now, that means I also schedule time to relax. We all know it's important to take breaks, but sometimes it can be hard to remember, especially when you're deep in the coding zone. Now, if it's on the calendar, I can look forward to it, which makes me more productive!&lt;/p&gt;

&lt;p&gt;I also like to schedule 'admin' time, which is a fancy way of saying 'check every social media site 5 times'. It's usually about an hour of time for me to check my finances, socials, and watch a &lt;a href="https://www.youtube.com/playlist?list=PLKtIunYVkv_RwB_yx1SZrZC-ddhxyXanh"&gt;Gourmet Makes&lt;/a&gt; video (you're welcome).&lt;/p&gt;

&lt;h1&gt;
  
  
  if it takes less than 5 minutes, just do it now
&lt;/h1&gt;

&lt;p&gt;A final tip that I find very effective is to just do the small things now. There are so many little things that might not be super urgent and thus are easy to keep putting off. Some examples from my own life include taking out the trash, putting away my laundry, or cleaning off my desk. All simple things that once completed, make me feel great!&lt;/p&gt;

&lt;p&gt;Well there we have it, my top three tips for keeping up your productivity. Thanks for reading, see you next week!&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>motivation</category>
    </item>
    <item>
      <title>Breaking Down DSAs: Count Primes</title>
      <dc:creator>Claire Muller</dc:creator>
      <pubDate>Sun, 11 Aug 2019 21:00:45 +0000</pubDate>
      <link>https://dev.to/clairemuller/breaking-down-dsas-count-primes-3d63</link>
      <guid>https://dev.to/clairemuller/breaking-down-dsas-count-primes-3d63</guid>
      <description>&lt;p&gt;Welcome back! All week I've been trying to think of a blog post idea that wasn't another algorithm breakdown, but yesterday I encountered a crazy cool one that I just want to talk about! The problem comes from the &lt;a href="https://leetcode.com/explore/interview/card/top-interview-questions-easy/"&gt;LeetCode collection&lt;/a&gt; that I've been working through, and it's called &lt;a href="https://leetcode.com/problems/count-primes/"&gt;count primes&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here's the problem: return the number of prime numbers less than a given integer, &lt;code&gt;n&lt;/code&gt;. So given &lt;code&gt;10&lt;/code&gt;, the function should return &lt;code&gt;4&lt;/code&gt;, as there are 4 prime numbers less than 10: 2, 3, 5, and 7.&lt;/p&gt;

&lt;p&gt;First, I had to refresh my memory on what a prime number even is (don't judge me). A quick google search told me that a prime number is a whole number greater than 1 whose only factors are 1 and itself. I also learned that a non-prime number is called a composite number! Fascinating.&lt;/p&gt;

&lt;p&gt;My first attempt (in JavaScript) was pretty straightforward. I created a helper function, &lt;code&gt;isPrime&lt;/code&gt; that simply accepts a number and returns a boolean. This function uses a for loop to iterate through every number from 2 up to the given number. I used the &lt;a href="https://www.w3schools.com/js/js_arithmetic.asp"&gt;modulo/remainder&lt;/a&gt; operator to check if the given number divided by the current number in the loop has a remainder of 0. If it does, that means the number is not prime so we can return &lt;code&gt;false&lt;/code&gt;. Otherwise, the function returns a boolean from &lt;code&gt;n &amp;gt; 1&lt;/code&gt;, to weed out 0 and 1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;isPrime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now my &lt;code&gt;countPrimes&lt;/code&gt; function can use my helper to, well, count the primes. I initiated a counter at 0, and since we want to count all the prime numbers &lt;em&gt;less than&lt;/em&gt; the given number &lt;code&gt;n&lt;/code&gt;, I subtract one from &lt;code&gt;n&lt;/code&gt; before I start a while loop. The loop passes &lt;code&gt;n&lt;/code&gt; into the helper, and if it returns &lt;code&gt;true&lt;/code&gt;, I iterate the counter. I then decrement &lt;code&gt;n&lt;/code&gt;, and do it all again, returning the final &lt;code&gt;primesCount&lt;/code&gt; at the end. Here's what that all looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;countPrimes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;primesCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isPrime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;primesCount&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;primesCount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Phew! I was feeling pretty good, but I knew there had to be a better way. It's just not efficient to check if every single number is prime, as doing so involves dividing the number by every single number less than it. That's a lot of checks! After failing to think of a more efficient solution, I turned to my trusty friend, Google.&lt;/p&gt;

&lt;p&gt;So here's where it gets crazy cool! I learned about the &lt;a href="https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes"&gt;Sieve of Eratosthenes&lt;/a&gt; and my mind was blown. This algorithm essentially starts at the first prime number, 2, and marks its multiples as composite (not prime). It then moves onto the next prime, and so on, until reaching the given limit.&lt;/p&gt;

&lt;p&gt;I understood how the algorithm worked but I still wasn't sure about the best way to implement it in JavaScript. Some more googling led me to &lt;a href="https://www.thepolyglotdeveloper.com/2015/04/determine-if-a-number-is-prime-using-javascript/"&gt;this&lt;/a&gt; great post from Nic Raboy.&lt;/p&gt;

&lt;p&gt;The idea is to create an array of booleans with a length of the given integer &lt;code&gt;n&lt;/code&gt;. Initially, every element will be marked as &lt;code&gt;true&lt;/code&gt;, except for &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;1&lt;/code&gt;, which are not prime.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;primes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;primes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now, we can start marking the prime multiples as false. I give all credit for this code to Nic, as this was pretty hard for me to wrap my head around. He creates a &lt;code&gt;limit&lt;/code&gt; variable which is the square root of the given integer &lt;code&gt;n&lt;/code&gt;. After a lot of thought, I realized that this avoids checking the array for multiples of numbers that are greater than &lt;code&gt;n&lt;/code&gt;. For example, if &lt;code&gt;n = 10&lt;/code&gt; we only need to look at the prime numbers less than its square root, which is 3.16. There's no need to look at the multiples of 5 and 7.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;limit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;primes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;primes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Finally, our array is complete and we can simply iterate through it, counting every &lt;code&gt;true&lt;/code&gt; instance, returning the final count!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;primes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;primes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Thanks for following along and I hope this was helpful to someone. I had a lot of fun learning along the way! Again, big thanks to &lt;a href="https://www.nraboy.com/"&gt;Nic Raboy&lt;/a&gt; for his post. See you next week!&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>javascript</category>
      <category>programming</category>
      <category>learning</category>
    </item>
    <item>
      <title>Breaking Down DSAs: Two Sum</title>
      <dc:creator>Claire Muller</dc:creator>
      <pubDate>Sun, 04 Aug 2019 17:21:11 +0000</pubDate>
      <link>https://dev.to/clairemuller/breaking-down-dsas-two-sum-2gc</link>
      <guid>https://dev.to/clairemuller/breaking-down-dsas-two-sum-2gc</guid>
      <description>&lt;p&gt;Another week, another blog post! I really enjoyed writing my &lt;a href="https://dev.to/clairemuller/breaking-down-dsas-valid-anagram-1m55"&gt;last post&lt;/a&gt; about solving a popular coding problem, valid anagram, and I thought I would try another this week. So today I'll be walking through my various solutions to the popular two sum problem, using JavaScript.&lt;/p&gt;

&lt;p&gt;There are a few different variations of this problem, but the one I'll be doing comes from &lt;a href="https://leetcode.com/problems/two-sum/"&gt;LeetCode&lt;/a&gt;. The problem: Given an array of integers, return the indices of the two numbers that add up to a given sum.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input: nums = [2, 7, 11, 15], sum = 9
Output: [0, 1]
Because nums[0] + nums[1] = 2 + 7 = 9
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I always like to start out with the most obvious brute force solution in order to make sure I have a good understanding of the problem. So my first solution was to simply use two nested for loops to check each combination of numbers. If adding the two numbers together equalled the given sum, then return the indices of those two numbers. If there's no combination, return an empty array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;twoSum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now I learned long ago that nested for loops have a runtime of O( n^2 ), which is not ideal. There's pretty much always a better, more efficient way, and it usually involves an object/hash table/dictionary/whatever your programming language of choice calls it.&lt;/p&gt;

&lt;p&gt;After thinking on this for a minute, I realized that I can iterate through the array and save each number and its index in an object, giving me this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// given nums = [2, 7, 11, 15]&lt;/span&gt;
&lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;While building this object, I can check to see if the current number's complement (the sum minus the current number) already exists in the object. To make it a little easier to read, I saved this target number to a variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hasOwnProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This way, if the two numbers are near the beginning of the array, we don't even need to check the rest of the array and can return. This solution gives us time and space of O(n), which is twice as fast as using nested for loops. The final solution looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;twoSum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// save target number to variable, easier to read&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="c1"&gt;// if the object has a key of the target number&lt;/span&gt;
    &lt;span class="c1"&gt;// return its index (the value) and current index of nums&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hasOwnProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// otherwise, create key value pair of the current number and its index&lt;/span&gt;
    &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Thanks for tuning in, and I'll catch you next week!&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>javascript</category>
      <category>learning</category>
      <category>programming</category>
    </item>
    <item>
      <title>Breaking Down DSAs: Valid Anagram</title>
      <dc:creator>Claire Muller</dc:creator>
      <pubDate>Sun, 28 Jul 2019 21:36:33 +0000</pubDate>
      <link>https://dev.to/clairemuller/breaking-down-dsas-valid-anagram-1m55</link>
      <guid>https://dev.to/clairemuller/breaking-down-dsas-valid-anagram-1m55</guid>
      <description>&lt;p&gt;Since graduating from the Flatiron School two months ago, I've been hard at work learning all I can about data structures and algorithms in preparation for the dreaded technical interview. I found a great &lt;a href="https://leetcode.com/explore/interview/card/top-interview-questions-easy/"&gt;collection on LeetCode&lt;/a&gt; of the top interview questions and have been slowly making my way through them.&lt;/p&gt;

&lt;p&gt;Anybody who's done these kinds of coding challenges knows that there are always multiple approaches and solutions with varying runtimes. I thought it would be helpful to me (and maybe someone else) if I talked through my different solutions to one of the first problems I did, and what I learned along the way. So today I'll be going through a classic question: valid anagram.&lt;/p&gt;

&lt;p&gt;The problem is this: given two strings, &lt;code&gt;s&lt;/code&gt; and &lt;code&gt;t&lt;/code&gt;, write a function to determine if &lt;code&gt;t&lt;/code&gt; is an &lt;a href="https://www.dictionary.com/browse/anagram"&gt;anagram&lt;/a&gt; of &lt;code&gt;s&lt;/code&gt;. For example, if &lt;code&gt;s = “anagram”&lt;/code&gt; and &lt;code&gt;t = “nagaram”&lt;/code&gt;, return &lt;code&gt;true&lt;/code&gt;. I'll be using JavaScript.&lt;/p&gt;

&lt;p&gt;My immediate thought was that if the strings' lengths aren't the same, then there's no way they can be anagrams, and thus we can quickly return &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Obviously, two strings can be the same length but contain different letters, so our function continues. My next (naive) thought was to turn the strings into arrays and sort them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then I could easily compare each letter by iterating through one array and checking it against the other. If the letters aren't the same, return &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If every letter passes this test, then the two strings are confirmed to be anagrams and we can return true! After submitting my solution and feeling pretty smart, LeetCode decided to crush my spirit by telling me that my solution's runtime only beat 47% of other JavaScript submissions.&lt;/p&gt;

&lt;p&gt;The great thing about LeetCode is that you see other people's solutions, and thus I fell down a rabbit hole. I discovered what some might call a 'sick one liner' that was similar to what my solution was doing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;From this solution I learned that my final step of comparing the two arrays using a for loop could be made easier by simply turning the sorted arrays back into strings using &lt;code&gt;.join()&lt;/code&gt;. This is because strings can be compared using an equality operator while arrays cannot.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;wow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;wow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="c1"&gt;// returns false;&lt;/span&gt;

&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;wow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;wow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// returns true;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Further research led me to learn quite a bit about optimizing my code's runtime. I learned that using &lt;code&gt;.sort()&lt;/code&gt;, while quick and easy to type, is pretty inefficient under the hood. Additionally, in a technical interview, you likely won't be able to use a method that does so much for you.&lt;/p&gt;

&lt;p&gt;I then learned a very important lesson about writing efficient functions: objects are king. Objects, or dictionaries in other programming languages, have a constant lookup time, O(1), and thus can be very helpful in optimizing code.&lt;/p&gt;

&lt;p&gt;So I set out to try solving this problem again using an object. I determined that I could iterate through one of the strings, using the object to keep track of the number of times each letter appeared. So given the string 'anagram', the object would become:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;n&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;g&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;r&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;m&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then I can iterate through the other string, checking first that the letter appears in the object, and if it does, subtracting one from its value. Here's what that looked like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// create empty object&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

&lt;span class="c1"&gt;// iterate through one string, counting letters&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// iterate through other string, checking the object has letter key&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// if letter is in object, subtract count&lt;/span&gt;
    &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;My solution worked and was faster than 95% of other JavaScript submissions! But there was one final thing I wanted to see if I could refactor. I knew there were other potentially cleaner ways to write my for loops so I did some digging and discovered &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of"&gt;&lt;code&gt;for...of&lt;/code&gt;&lt;/a&gt;. I refactored my two for loops and the result was a lot less typing and clearer code!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// original for loop, iterating over the string, checking the object for each letter&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// same loop using for...of syntax&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;letter&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I should note that &lt;code&gt;for..of&lt;/code&gt; and the similar &lt;code&gt;for...in&lt;/code&gt; are newer to JavaScript and thus aren't fully supported everywhere. But for my purposes, it wasn't a problem. So my final function looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;isAnagram&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;letter&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;letter&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And that's all folks! I had a great time refactoring and learned a lot along the way. Catch you next week!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>programming</category>
      <category>learning</category>
    </item>
    <item>
      <title>Tips for Perfecting Your Online Presence</title>
      <dc:creator>Claire Muller</dc:creator>
      <pubDate>Mon, 13 May 2019 18:56:52 +0000</pubDate>
      <link>https://dev.to/clairemuller/tips-for-perfecting-your-online-presence-1cjd</link>
      <guid>https://dev.to/clairemuller/tips-for-perfecting-your-online-presence-1cjd</guid>
      <description>&lt;p&gt;As I start my last three weeks at the &lt;a href="http://flatironschool.com"&gt;Flatiron School&lt;/a&gt; in Seattle, the pressure of starting the job search is mounting. Having never applied for technical roles before, I’ve been asking anyone and everyone for their advice and any tips they have to make the search smoother. The number one thing I hear is that your online presence should be immaculate. So I thought for my blog post I would gather up the best advice I’ve received on this topic!&lt;/p&gt;

&lt;h2&gt;
  
  
  Private or Professional?
&lt;/h2&gt;

&lt;p&gt;The quickest way to assess your online presence is to simply Google your name, because recruiters and hiring managers surely will. If you have a fairly common name, try adding your location to the search for better results. Any social media accounts you have should either be private or otherwise display general professionalism. When in doubt, go private.&lt;/p&gt;

&lt;p&gt;Facebook and Instagram are good examples of accounts you might want to make private; you shouldn’t need to worry about every post coming across as unprofessional. Twitter is a bit of a grey area; lots of developers use it as part of their brand, as it’s an easy way to connect with companies and keep up to date with trends in tech. Make the decision that feels right for you, or consider creating a separate private account solely for following your friends.&lt;/p&gt;

&lt;h2&gt;
  
  
  Clean It Up
&lt;/h2&gt;

&lt;p&gt;Specific to developers, a solid GitHub profile is key, as it is the main place that hiring managers will look. Your profile should have a clear picture, location, and a link to your personal website or blog (if you don’t have either, read on). Take a few minutes to pin your favorite or most impressive projects to your profile. These should all have a clear name, description, and README. Bonus points for images or gifs of the project in action.&lt;/p&gt;

&lt;p&gt;LinkedIn is another important tool that recruiters will absolutely look at. Make sure everything is up to date, follow everyone you know and ask them to endorse your skills. There are tons of things you can add to your LinkedIn: links to projects, images of said projects, links to your blog or personal site, recommendations, and other achievements. The more robust your profile, the better you look to hiring managers. Tons of people get jobs through LinkedIn!&lt;/p&gt;

&lt;h2&gt;
  
  
  Set Up a Personal Site
&lt;/h2&gt;

&lt;p&gt;Finally, if you don’t have a blog or personal website, get on it! It’s probably obvious, but I like &lt;a href="http://dev.to"&gt;dev.to&lt;/a&gt; as a blogging platform mainly because it’s specific to developers. There’s a wonderful community here and most people are supportive and welcoming. I’ve gotten some great feedback and connections with just a few blog posts!&lt;/p&gt;

&lt;p&gt;A personal website is definitely a bigger endeavor, but having your own dedicated space on the internet will set you apart from those applicants that don’t. Your website can be a one-stop shop for all of the information you want a hiring manager to see: your resume, links, and project walkthroughs, all laid out how you want. For quick and easy set up, I like &lt;a href="https://www.squarespace.com/"&gt;Squarespace&lt;/a&gt;, but there are plenty of other options out there. &lt;/p&gt;

&lt;p&gt;You should &lt;em&gt;absolutely&lt;/em&gt; buy a domain name that’s your first and last name, or some variation. If yourname.com is taken, try .me or .io. I bought my domain name, &lt;a href="https://www.clairemuller.me/"&gt;clairemuller.me&lt;/a&gt; (still working on it) through Squarespace for $20; after paying for this and hosting, the total cost was around $140. This might be a bit much for some people, but I think it’s a worthwhile investment that will pay off in the long run.&lt;/p&gt;

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

&lt;p&gt;I hope these tips help you get ready for your job search, and feel free to comment with any tips you might have :) Happy coding!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>career</category>
    </item>
    <item>
      <title>4 Things I Learned From Building My First Site Solo</title>
      <dc:creator>Claire Muller</dc:creator>
      <pubDate>Wed, 24 Apr 2019 20:34:28 +0000</pubDate>
      <link>https://dev.to/clairemuller/4-things-i-learned-from-building-my-first-site-solo-1e26</link>
      <guid>https://dev.to/clairemuller/4-things-i-learned-from-building-my-first-site-solo-1e26</guid>
      <description>&lt;p&gt;Last week me and my fellow cohort mates at Flatiron School Seattle finished our module 3 projects; the assignment was to build a single-page application using vanilla Javascript and a Ruby on Rails backend. The rest was pretty much up to us, and I decided to make &lt;a href="https://clairemuller.github.io/jeoparody/" rel="noopener noreferrer"&gt;Jeoparody&lt;/a&gt;! This was the first website I built all by myself, and I learned a lot from it. So for my blog post I thought it would be helpful to write about the top things I learned.&lt;/p&gt;

&lt;h1&gt;
  
  
  CSS is weird
&lt;/h1&gt;

&lt;p&gt;Going into this project, I felt fairly confident in my CSS skills. I’d worked on the &lt;a href="https://www.codecademy.com/learn/learn-css" rel="noopener noreferrer"&gt;Codecademy CSS Course&lt;/a&gt; and tinkered around in the console, so I thought it was pretty straightforward. When you don’t know what you don’t know…&lt;/p&gt;

&lt;p&gt;My biggest struggle was figuring out how to vertically center text inside a div. ‘Why is this so hard?’ I asked myself after spending at least an hour adjusting the padding, margin, height and width. I finally discovered that simply wrapping the text in a p tag will do the trick! Unless...the text is longer and wraps to become multi-line. Still haven’t figured this one out.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fn9caksq1gd2504ihmyaf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fn9caksq1gd2504ihmyaf.png" alt="CSS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Seed smart
&lt;/h1&gt;

&lt;p&gt;While we’re on the topic of things I &lt;em&gt;thought&lt;/em&gt; I had down pat: seeding my database. I found this awesome API, &lt;a href="http://jservice.io/" rel="noopener noreferrer"&gt;jService&lt;/a&gt;, that has every clue and category from every season of Jeopardy. That’s roughly 185,000 clues! I was pumped! I set up my Clue and Category models, figured out the best way to iterate through each page of the API, and the seeding began.&lt;/p&gt;

&lt;p&gt;Fifteen minutes in, seeding failed! I quickly learned that one shouldn’t assume an API with 100,000+ entries is perfect. Tons of clues were duplicated, there were empty strings, missing values, you name it. After a lot of trial and error, the solution was to create two if statements that check each clue before it’s added to the database. The first one makes sure that the clue actually has the keys I want: question, answer, and category. The second if statement ensures that the values aren’t just empty strings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;clues.each do |clue|
  if clue.key?("question") &amp;amp;&amp;amp; clue.key?("answer") &amp;amp;&amp;amp; clue.key?("category")
    if !clue["question"].empty? &amp;amp;&amp;amp; !clue["answer"].empty? &amp;amp;&amp;amp; !clue["category"]["title"].empty?
      create_clue(clue)
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Event listeners are picky
&lt;/h1&gt;

&lt;p&gt;I haven’t had a lot of experience using event listeners, but they’re obviously an important thing to master. The first one that I implemented on my website was pretty straightforward. When a user first comes to the page, they put in their username and click the submit button. The event listener hears the ‘click’ and does its thing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById('submit').addEventListener("click", function(e){
  e.preventDefault();
  username = document.getElementById('username').value.toLowerCase();
  findUser(username);
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There was no need to ‘remove’ this event listener because the div that it’s inside is hidden once the user logs in. Easy! The next event listener I used was for each of the clue divs. I had figured out how to remove the dollar amount from the div once a user had clicked it, but the event listener remained. I tried a few things and eventually asked for some help. My instructor gave me the very simple solution of simply adding a class of ‘clicked’ to a clue div that had been clicked. This allowed me to write the following inside the event listener:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (clueDiv.classList.contains('clicked')) {
  return;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So once again, the event listener still exists on each clue div, but if a user clicks on one that they’ve already clicked on, it will simply return. Easy! My final event listener is the one that gave me the most trouble. Once a user has clicked on a clue, a div appears that asks if they got the question right or wrong.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbexk0wfb9brb961kxei4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbexk0wfb9brb961kxei4.png" alt="Yes or No"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I added an event listener that listens for a keydown of ‘Y’ or ‘N’ and went on my merry way. I soon realized that a user could continue to press ‘Y’ long after they’d finished the clue, and their score could increase forever! Thus, I finally had to tackle removing an event listener. After much trial and error, I discovered that removeEventListener is picky. Until now, I had been writing the whole function inside of the event listener, instead of referencing a separate function. This doesn’t fly when you try to remove the listener! In short, this was the only solution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.body.addEventListener("keydown", yesOrNo);
document.body.removeEventListener("keydown", yesOrNo);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Comments are necessary
&lt;/h1&gt;

&lt;p&gt;I’ve always been pretty good about writing comments in my code, but it wasn’t until I started this project that I realized just how necessary they are. After I had my backend all set up, I wrote that first fetch request and it began...I was in the zone.&lt;/p&gt;

&lt;p&gt;When I’m in the zone, coding my little heart away, it’s easy to forget to write a quick comment to help out my future self. But it’s so important! Because even if I think I know exactly what all my code is doing, I’ll eventually be going to sleep. And the next day, when I’m reading my code, I have no idea what’s going on. So don’t forget to leave yourself some notes to save future you from future headaches.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;To conclude, I learned a lot from building &lt;a href="https://clairemuller.github.io/jeoparody/" rel="noopener noreferrer"&gt;my first website&lt;/a&gt;. If you’re new to coding, I would highly recommend building a single-page application. It’s great practice and helped solidify my knowledge of HTML, CSS and Javascript. Happy coding!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What is a Gem? Part 2</title>
      <dc:creator>Claire Muller</dc:creator>
      <pubDate>Mon, 01 Apr 2019 23:28:43 +0000</pubDate>
      <link>https://dev.to/clairemuller/what-is-a-gem-part-2-leo</link>
      <guid>https://dev.to/clairemuller/what-is-a-gem-part-2-leo</guid>
      <description>&lt;p&gt;Welcome back to my series on gems in Ruby! &lt;a href="https://dev.to/clairemuller/what-is-a-gem-part-1-2pf1"&gt;Last time&lt;/a&gt; I went back to the basics, and learned that a gem is Ruby's version of a package, which is simply a collection of files. Gems are frequently used to add functionality to a Ruby application or the CLI. &lt;a href="https://rubygems.org/" rel="noopener noreferrer"&gt;RubyGems&lt;/a&gt; is the package manager for Ruby - there's currently 10,023 gems to choose from!&lt;/p&gt;

&lt;h1&gt;
  
  
  Gem Structure
&lt;/h1&gt;

&lt;p&gt;A gem’s structure should look fairly familiar; most come with lib, test/spec, and bin directories, as well as a README, Rakefile, and gemspec. Here’s a tree breakdown of the gem &lt;a href="https://rubygems.org/gems/tux/versions/0.3.0" rel="noopener noreferrer"&gt;tux&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fd2gyrrr0m3msbgpzr346.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fd2gyrrr0m3msbgpzr346.png" alt="tux gem structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  lib
&lt;/h3&gt;

&lt;p&gt;The lib directory contains all of the code that makes up the program. Standard practice is to create a file with the same name as the gem just inside the lib directory. This file is considered the ‘root’ file, and contains the main module for the program. This is the file that is loaded when you ‘require’ the gem.&lt;/p&gt;

&lt;p&gt;Since this root file can easily get crowded, it’s common to create a directory inside lib, also with the same name as the gem. This folder will store all other files related to the module, and will need to be required at the top of the root file.&lt;/p&gt;

&lt;h3&gt;
  
  
  test/spec &amp;amp; bin
&lt;/h3&gt;

&lt;p&gt;The test or spec directory is pretty straightforward, it stores all the test files! A marker of a good gem is the inclusion of these files; other developers will trust your code more if it has solid tests. With this we need a Rakefile, which allows us to run ‘rake test’ or simply ‘rake’ to run the test suite. The bin directory contains an executable file that’s loaded into a user’s PATH; the standard is to give this file the same name as the gem.&lt;/p&gt;

&lt;h3&gt;
  
  
  Gemspec
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8f36ks6mdtnge2wt9q60.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8f36ks6mdtnge2wt9q60.png" alt="tux gemspec"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The .gemspec file contains all the information about the gem, including its name, version, files, author(s), and a brief summary. While these fields are required, a gem creator can choose to add additional information, like a contact email, license(s), required ruby version and other metadata.&lt;/p&gt;

&lt;h1&gt;
  
  
  Useful Commands
&lt;/h1&gt;

&lt;p&gt;Here are a few commands that I found useful in my learning:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gem install &amp;lt;gem name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Does what it says on the tin, installs the gem! &lt;code&gt;i&lt;/code&gt; can be used as an alias for &lt;code&gt;install&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gem list&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Shows every gem that is installed locally, with their versions.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gem update&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Also pretty straightforward! If you run this command without a specific gem name, it will update all your gems to the newest version.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gem cleanup&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This one's great if you're a little OCD like me. It removes all but the latest version of each gem, unless that version is required elsewhere to meet a dependency. You can also run this command on specific gems.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gem environment&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command gives you some useful information, like your RubyGems and ruby versions, as well as where gems are installed on your computer. &lt;code&gt;env&lt;/code&gt; can be used as an alias for &lt;code&gt;environment&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;To summarize what I’ve learned about gems: they’re essentially bundles of code that can improve your projects by adding functionality or cool features. There are a ton of helpful gems out there, and &lt;a href="https://rubygems.org/" rel="noopener noreferrer"&gt;RubyGems&lt;/a&gt; is definitely the best resource. Thanks for reading!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>programming</category>
      <category>gems</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What is a Gem? Part 1</title>
      <dc:creator>Claire Muller</dc:creator>
      <pubDate>Tue, 19 Mar 2019 16:03:20 +0000</pubDate>
      <link>https://dev.to/clairemuller/what-is-a-gem-part-1-2pf1</link>
      <guid>https://dev.to/clairemuller/what-is-a-gem-part-1-2pf1</guid>
      <description>&lt;p&gt;Ruby gems, like a lot of things in ruby, can seem pretty magical at times. How is it possible that I can type ‘gem install rails’ into my terminal and be able to create a web application in a matter of minutes? What is this sorcery? I’m on a mission to find out!&lt;/p&gt;

&lt;h1&gt;
  
  
  Back to the Basics
&lt;/h1&gt;

&lt;p&gt;To really understand a gem, we have to take a few steps back. Basically every aspect of computing involves files; a single file can contain a little or a lot of information. For us to make programs and do cool stuff, files have to be used together. It can quickly get very confusing to keep track of what every file is doing. Enter: packages. A package is simply a collection of files and metadata (data that describes other data).&lt;/p&gt;

&lt;h1&gt;
  
  
  Gems
&lt;/h1&gt;

&lt;p&gt;In Ruby, these packages are called gems. Gems contain code, documentation, and a gemspec. One of the most widely used gems is &lt;a href="https://bundler.io/"&gt;bundler&lt;/a&gt;, which is able to look in your Gemfile and download the correct version you need for your program. Another popular gem, &lt;a href="https://rubyonrails.org/"&gt;rails&lt;/a&gt;, is an entire web application framework that makes building web apps quick and easy.&lt;/p&gt;

&lt;h1&gt;
  
  
  Package Management
&lt;/h1&gt;

&lt;p&gt;Just like files, packages can get messy to deal with. A package manager, as the name implies, is software that manages these packages for you. A great example of a package manager that we’ve all used is an app store. A user can easily search for, install, or delete an app without having to do the dirty work of checking dependencies or manually installing each file within the package. Everything is handled for you, so you can get to the good stuff! With the release of Ruby 1.9 in late 2007, the package manager &lt;a href="https://rubygems.org/"&gt;RubyGems&lt;/a&gt; became Ruby’s default package manager.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;There is a lot more to be said about gems! For my next post, I’ll dive deeper into what makes up a gem, including the structure and gemspec file. But to summarize for now: gems are packages used in ruby to make programming easier for us. Catch you next time!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>programming</category>
      <category>gems</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Refactoring My Old Ruby Code</title>
      <dc:creator>Claire Muller</dc:creator>
      <pubDate>Mon, 18 Mar 2019 15:54:09 +0000</pubDate>
      <link>https://dev.to/clairemuller/refactoring-my-old-ruby-code-54in</link>
      <guid>https://dev.to/clairemuller/refactoring-my-old-ruby-code-54in</guid>
      <description>&lt;p&gt;For my first blog post I thought it would be fun to look back and refactor some code I wrote when I first started learning Ruby. It’s from a lesson that any Flatiron School student will remember well: &lt;a href="https://learn.co/lessons/advanced-hashes-hashketball"&gt;Hashketball&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;First, you’re given a bunch of information about two basketball teams and told to build a nested hash. Then, you’re instructed to write methods that return certain information about a player or team. For example: player_numbers takes in an argument of a team name and returns an array of the jersey numbers for that team.&lt;/p&gt;

&lt;p&gt;At the time, this lesson was really hard for me. I’d never worked with such a big nested hash before and was pretty new to the idea. You’re instructed to use .each and binding.pry to get comfortable with iteration. This was great at the time, as it helped me learn what to expect from iteration and I got really comfortable using binding.pry.&lt;/p&gt;

&lt;p&gt;There are seven methods to write, and my original code came out to 128 lines, with tons of repetition and if statements. Now that I’m a few months into learning Ruby, I know there are much better, more efficient ways to write this code. So I’m going to take my knowledge of helper methods to shorten it!&lt;/p&gt;




&lt;p&gt;The first thing I want to do is create some helper methods to make everything easier on myself. My previous code had me iterating through the game hash, then through that data, then through that data… but now I know the programming rule DRY, don’t repeat yourself.&lt;/p&gt;

&lt;p&gt;I’m going to write a method, all_players, which simply takes the home team’s players and the away team’s players and merges them into one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def all_players
  game_hash[:home][:players].merge(game_hash[:away][:players])
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now I can access all of the players and their stats in one method, no more repetitive iteration. I’m going to use this method to refactor the player_stats method. This one takes an argument of a player’s name and returns only their stats.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def player_stats(name)
  all_players[name.to_sym]
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This method is part of the test but is in itself a helper method. I can use it to simplify num_points_scored and shoe_size, making them much easier to read. They both take an argument of a player’s name and return one of their stats.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def num_points_scored(name)
  player_stats(name)[:points]
end

def shoe_size(name)
  player_stats(name)[:shoe]
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;How beautiful! How clean! Next up we have some methods that take an argument of a team name, so I’ll create two more helpers for this. One that returns both team’s data, and another that takes an argument of a team’s name and returns only its data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def all_teams
  game_hash.values
end

def find_team(team_name)
  all_teams.find { |team| team[:team_name] == team_name }
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Wonderful, now I can refactor the team_names method. This one simply returns both team’s names, so I can use my all_teams helper method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def team_names
  all_teams.map { |team| team[:team_name] }
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So satisfying! Now I can use my other helper, find_team to shorten both team_colors and player_numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def team_colors(team_name)
  find_team(team_name)[:colors]
end

def player_numbers(team_name)
  find_team(team_name)[:players].map {|name, stats| stats[:number]}
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Finally we have the monster method big_shoe_rebounds, which is just painful to look at:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def big_shoe_rebounds
  shoe_sizes_w_names = {}
  game_hash.each do |location, team_data|
    team_data.each do |attribute, data|
      if attribute == :players
        data.each do |name, stats|
          stats.each do |k, v|
            if k == :shoe
              shoe_sizes_w_names[name] = v
            end
          end
        end
      end
    end
  end
  player_w_big_shoes = shoe_sizes_w_names.key(shoe_sizes_w_names.values.max)
  game_hash.each do |location, team_data|
    team_data.each do |attribute, data|
      if attribute == :players
        data.each do |name, stats|
          if name == player_w_big_shoes
            stats.each do |k, v|
              if k == :rebounds
                return v.to_i
              end
            end
          end
        end
      end
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Yikes. That’s 34 lines for one method! The big problem here is that this method is doing two separate things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;finding the player with the biggest shoe size&lt;/li&gt;
&lt;li&gt;finding that player’s number of rebounds&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There’s a philosophy in programming: a method should do one thing, and do it well. With this in mind, I decided to first create a method that finds the player with the biggest shoe size.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def player_w_biggest_feet
  all_players.max_by { |name, stats| stats[:shoe] }
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now I can use this method to find their rebounds, and pass the final test. However, I could also use it to find any other data about the player with the biggest feet, if I ever wanted to.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def big_shoe_rebounds
  player_w_biggest_feet[1][:rebounds]
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And that’s it! In the end, I took my code from 128 lines down to 43, and every method is only 3 lines. The result is the same, but now the code is much easier to read and understand.&lt;/p&gt;




&lt;p&gt;To summarize, I learned a lot about the basics of Ruby the first time I did this lesson. Knowing how .each works is really important and builds a great foundation for understanding more abstract methods like .map and .find. Refactoring and working with it a second time around was a lot more fun than I was expecting! It can be a little cringe-inducing to look back at your early code, but a lot can be learned from it. Thanks for reading!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>programming</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
