<?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>Forem: Steph</title>
    <description>The latest articles on Forem by Steph (@stephjs).</description>
    <link>https://forem.com/stephjs</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%2F59731%2Ff311e711-847c-43db-9941-6f009c927c2e.jpeg</url>
      <title>Forem: Steph</title>
      <link>https://forem.com/stephjs</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/stephjs"/>
    <language>en</language>
    <item>
      <title>Building a Sunday scaries Messaging Service</title>
      <dc:creator>Steph</dc:creator>
      <pubDate>Mon, 11 Jan 2021 03:10:15 +0000</pubDate>
      <link>https://forem.com/stephjs/building-a-sunday-scaries-messaging-service-29np</link>
      <guid>https://forem.com/stephjs/building-a-sunday-scaries-messaging-service-29np</guid>
      <description>&lt;h2&gt;
  
  
  What I built and why
&lt;/h2&gt;

&lt;p&gt;My friends and I get Sunday scaries, the anxiety that sets in on Sunday nights with the impending end of the weekend and return to our dev jobs on Monday. Lots of memes and sobbing emoji are exchanged on Sunday nights, but there's just no support on Monday mornings. 🥺 So I built SMS HMU. What is SMS HMU you may ask? SMS HMU stands for "Sunday scaries Messaging Service to Hype Mondays Up." This is an automated solution to send my friends and me funny / motivational text messages every Monday morning to make the beginning of the week a little less painful. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.reddit.com/r/funny/comments/6jhuek/the_sunday_scaries_in_graph_form/"&gt;Sunday Scaries in graph form&lt;/a&gt; by u/ToothMan22&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yhfmIj8D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.redd.it/v987eimxxv5z.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yhfmIj8D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.redd.it/v987eimxxv5z.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Category Submission: Random Roulette 🥳
&lt;/h3&gt;

&lt;h3&gt;
  
  
  App Link
&lt;/h3&gt;

&lt;p&gt;API: &lt;a href="https://github.com/stephjs/sms-hype-mondays-up"&gt;https://github.com/stephjs/sms-hype-mondays-up&lt;/a&gt;&lt;br&gt;
Cron job to send out SMS HMU every Monday: &lt;a href="https://github.com/stephjs/sms-hmu-cron-job"&gt;https://github.com/stephjs/sms-hmu-cron-job&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Screenshots
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J1scgPwe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pr1bi6kr4oqguu1fpcyk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J1scgPwe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pr1bi6kr4oqguu1fpcyk.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Description
&lt;/h3&gt;

&lt;p&gt;Here are three messages I sent to my friends with my SMS HMU API. The real fun will start tomorrow (Monday) when the cron job executes the code and starts sending weekly messages to everyone.&lt;/p&gt;

&lt;h3&gt;
  
  
  Link to Source Code
&lt;/h3&gt;

&lt;p&gt;API: &lt;a href="https://github.com/stephjs/sms-hype-mondays-up"&gt;https://github.com/stephjs/sms-hype-mondays-up&lt;/a&gt;&lt;br&gt;
Cron job that sends my friends their SMS HMU every Monday: &lt;a href="https://github.com/stephjs/sms-hmu-cron-job"&gt;https://github.com/stephjs/sms-hmu-cron-job&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Permissive License
&lt;/h3&gt;

&lt;p&gt;MIT&lt;/p&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;(What made you decide to build this particular app? What inspired you?)&lt;/p&gt;

&lt;p&gt;I built this on a Sunday. The scaries are just now setting in. I work as a frontend developer. You may have noticed this has no frontend. I wanted to build something that would be fun for my friends and a bit different than what I work on day to day.&lt;/p&gt;

&lt;h3&gt;
  
  
  How I built it
&lt;/h3&gt;

&lt;p&gt;(How did you utilize DigitalOcean’s App Platform? Did you learn something new along the way? Pick up a new skill?)&lt;/p&gt;

&lt;p&gt;I had never used DigitalOcean before! I used DO to deploy my Node.js API and cron job. I was impressed by how helpful the starter docs were, and how intuitive the DigitalOcean UI makes deploying projects from Github. I had also never actually written a cron job! So that was fun to figure out. The &lt;a href="https://www.npmjs.com/package//node-cron"&gt;node-cron package&lt;/a&gt; + &lt;a href="https://crontab.guru/#30_7_*_*_1"&gt;crontab guru&lt;/a&gt; made it painless.&lt;/p&gt;

</description>
      <category>dohackathon</category>
      <category>aws</category>
      <category>node</category>
      <category>lol</category>
    </item>
    <item>
      <title>Post-Grad Job Hunting Guide</title>
      <dc:creator>Steph</dc:creator>
      <pubDate>Tue, 18 Jun 2019 23:25:10 +0000</pubDate>
      <link>https://forem.com/stephjs/post-grad-job-hunting-guide-43bg</link>
      <guid>https://forem.com/stephjs/post-grad-job-hunting-guide-43bg</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4ny0f3Ly--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img1.wsimg.com/isteam/ip/cdeab369-f035-4ec4-93d6-19d310c7afba/391D2F51-78DA-41B9-98EB-1033D0173601.JPEG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4ny0f3Ly--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img1.wsimg.com/isteam/ip/cdeab369-f035-4ec4-93d6-19d310c7afba/391D2F51-78DA-41B9-98EB-1033D0173601.JPEG" alt="graduation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations to the Class of 2019. You did it! The tassel was worth the hassle! I attended multiple graduations this weekend and though I really enjoyed the messages from the grad speakers, [insert motivational Dr. Seuss quote here], I didn’t hear a lot of actionable advice on how to handle what comes next: the job hunt. I’m sure you’ve heard enough of the “follow your heart” and the “life’s about the journey you take and the mistakes you make” sentiment at this point, so here are some things you can do right now to land your first job out of college.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Websites like LinkedIn and Indeed are great for finding listings you are interested in. After you’ve found a job rec on one of these sites, Google the company to apply to those roles directly on their Careers site. It may take a little more effort, but this is your best chance to get your application reviewed by a human rather than being lost in the pool of 1-click apply LinkedIn profiles.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your college degree qualifies you for MOST entry level jobs (requiring less than 3 years of experience). The whole point of an entry level job is that it’s meant to be filled by someone without much practical experience. Even if your major doesn’t completely align with job requirements, you can still be a great candidate based on your transferrable skills and aptitude to learn. Enroll in a course on a site like Udemy (~$10 during a sale) to continue lifelong learning and pick up a new skill. This could be anything you’re interested in from video editing to coding to project management that adds value to companies you are targeting.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Class projects, volunteering, research, and club/org activity are fair game to use on your resume and during interviews. These come in especially handy for those “tell me about a time when you…” types of situational story interview questions. Create STAR response charts for these types of experiences and keep them handy to review the day before a big interview.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update your resume using Google’s resume formula to describe your experience. “Accomplished [X] as measured by [Y] by doing [Z].” The more actual metrics you can use to emphasize the scale of what you’ve worked on, the better. How much money did you raise by planning that fundraiser? By what percentage did you increase retention as your club’s social chair? How many students did you tutor and how much better was their next grade?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A little enthusiasm goes a long way in the interview process! Make sure to mention that you are excited about the industry, company, and job opportunity you are applying for. Interviewers are looking for a candidate who is trainable and will be a good culture fit with the team. Read the company’s “culture” statement and check if they are active on social media to find out some recent wins you can bring up while interviewing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Find alumni from your school that are working in industries that interest you. Send them a message on LinkedIn asking if they are willing to hop on a 30m call for an informal informational interview about their job and company. This is a great way to get some insight into what a job is like and maybe even get a recommendation. Sample message: “Hi [person]! I am a fellow [school] graduate class of [year] and was interested in hearing more about your career as a [job title]. Based on my experience [list relevant experience/interest/common major] I think [the industry] could be a good fit for me. Would you be willing to schedule a 30 minute informational interview with me? I have some questions ready about your day-to-day and would love to hear more about your career up to this point."&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Apply broadly and don’t get discouraged if you aren’t hearing back from every company. I applied to 50+ jobs after graduation and started the interview process at 3. Job hunting (especially for your first job) is a numbers game. Create a Trello board to keep track of companies you’ve applied to and where in the process you are. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Have some more job hunting advice for recent grads? Leave it in the comments! Want more? You can find me on instagram &lt;a href="https://instagram.com/_steph.js/"&gt;@_steph.js&lt;/a&gt; where I post dev humor and a sneak peak into my day-to-day. I also have a blog &lt;a href="https://stephjs.com/blog"&gt;stephjs.com&lt;/a&gt; for longer, more in-depth posts. &lt;/p&gt;

</description>
      <category>career</category>
      <category>graduation</category>
    </item>
    <item>
      <title>Linear and Binary Search in JavaScript</title>
      <dc:creator>Steph</dc:creator>
      <pubDate>Wed, 16 May 2018 23:55:43 +0000</pubDate>
      <link>https://forem.com/stephjs/linear-and-binary-search-in-javascript-4b7h</link>
      <guid>https://forem.com/stephjs/linear-and-binary-search-in-javascript-4b7h</guid>
      <description>&lt;p&gt;This week I started reading Grokking's &lt;a href="https://www.manning.com/books/grokking-algorithms" rel="noopener noreferrer"&gt;Algorithms&lt;/a&gt;, an illustrated guide for programmers and other curious people. So far it's a fantastic read -- full of practical examples with fun drawings to explain technical concepts in understandable ways. Code examples in the book are written in Python. I'm primarily a JavaScript developer, so I thought I'd work my way through the book and show you my JavaScript code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Searching through Arrays
&lt;/h2&gt;

&lt;p&gt;You're searching for something in a list. You aren't sure if it is actually in the list, but if it is, you'd like to know where it is. In this case we have a rainbow and we are looking for a specific color.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;rainbow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;yellow&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;indigo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;violet&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;h4&gt;
  
  
  The &lt;del&gt;Easy&lt;/del&gt;   &lt;del&gt;Bad&lt;/del&gt; Linear Way
&lt;/h4&gt;

&lt;p&gt;You may be thinking, "Easy! I'll just loop through each element of the array and return the match!" This works, and is called a linear search.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;linearSearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;elToFind&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;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;elToFind&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;linearSearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rainbow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;green&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 3&lt;/span&gt;
&lt;span class="nf"&gt;linearSearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rainbow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;white&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 null&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Buttttttt, (and the size of this but is dependent on the size of your data set) there's a performance tradeoff here. You have to loop through every single element to find out that yours isn't part of the array. When we are only talking 7 colors, this is nbd but what if we were going through an array of thousands or millions of records? &lt;a href="https://media.giphy.com/media/1DagSuFvJ1BlK/giphy.gif" rel="noopener noreferrer"&gt;Forget it.&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Binary Search
&lt;/h4&gt;

&lt;p&gt;A &lt;a href="https://en.wikipedia.org/wiki/Binary_search_algorithm" rel="noopener noreferrer"&gt;binary search&lt;/a&gt; takes in a sorted array and looks for a specific element. If the element is present in the array, the search returns the index of the element; otherwise it returns null. Because the array has already been sorted, the search can compare the target search element to the element in the middle of the array, eliminating half the search range at a time. Think of it as a game of hotter-colder.&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%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fthumb%2F8%2F83%2FBinary_Search_Depiction.svg%2F470px-Binary_Search_Depiction.svg.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%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fthumb%2F8%2F83%2FBinary_Search_Depiction.svg%2F470px-Binary_Search_Depiction.svg.png" title="binary search image from Wikipedia" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Retrying the Rainbow Example with Binary Search
&lt;/h4&gt;

&lt;p&gt;You and I understand the ROY G. BIV ordering of the aforementioned rainbow, but your browser didn't go to Kindergarten. In order to perform a binary search on the rainbow, it needs to be (alphabetically) sorted. Luckily, we have JavaScript's built in sort method for arrays.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;rainbow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;yellow&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;indigo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;violet&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;sortedRainbow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;rainbow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;span class="c1"&gt;// returns ["blue", "green", "indigo", "orange", "red", "violet", "yellow"];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great! Now we have something we can pass a to  binary search.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;binarySearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sortedArray&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;elToFind&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;lowIndex&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="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;highIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sortedArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;lowIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;highIndex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;midIndex&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="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;lowIndex&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;highIndex&lt;/span&gt;&lt;span class="p"&gt;)&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sortedArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;midIndex&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;elToFind&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;midIndex&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sortedArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;midIndex&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;elToFind&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;lowIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;midIndex&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;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;highIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;midIndex&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;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;sortedRainbow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;indigo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;violet&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;yellow&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nf"&gt;binarySearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sortedRainbow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;green&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 1&lt;/span&gt;
&lt;span class="nf"&gt;binarySearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sortedRainbow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;white&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 null&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay, that was a lot. Or maybe you're a search whiz and you completely understood that. Let's take the binary search line by line. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The &lt;strong&gt;binarySearch&lt;/strong&gt; function takes in a &lt;strong&gt;sortedArray&lt;/strong&gt; and an element you are searching for (&lt;strong&gt;elToFind&lt;/strong&gt;). &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;During the search, you'll be keeping track of the range you are searching through with a starting &lt;strong&gt;lowIndex&lt;/strong&gt; of 0 and a starting &lt;strong&gt;highIndex&lt;/strong&gt; of the number of elements in the sorted array. At the start of the search, the range will span the entire array.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;the &lt;strong&gt;while&lt;/strong&gt; loop executes until the search has been narrowed to one element&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;to find the index of the element between the &lt;strong&gt;lowIndex&lt;/strong&gt; and the &lt;strong&gt;highIndex&lt;/strong&gt;, average these two value (Note: use Math.floor to round this value down because the &lt;strong&gt;midIndex&lt;/strong&gt; must be an integer)&lt;/li&gt;
&lt;li&gt;if you've found the element, return the index&lt;/li&gt;
&lt;li&gt;if the current element is less than (alphabetically before) the element you're searching for, increase the &lt;strong&gt;lowIndex&lt;/strong&gt; to one more than the &lt;strong&gt;midIndex&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;if the current element is greater than (alphabetically after) the element you're searching for, decrease the &lt;strong&gt;highIndex&lt;/strong&gt; to one less than the &lt;strong&gt;midIndex&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;if the element doesn't exist in the array, return null&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Up Next
&lt;/h3&gt;

&lt;p&gt;Now that we've looked at two search methods (linear and binary) we need a way to measure their performance against one another. In my next post I'll look at  logarithms (throwback to Algebra 2) and Big O notation. Stay tuned!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>computerscience</category>
      <category>binarysearch</category>
    </item>
  </channel>
</rss>
