<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mark Sauer-Utley on Medium]]></title>
        <description><![CDATA[Stories by Mark Sauer-Utley on Medium]]></description>
        <link>https://medium.com/@mark.utley.713?source=rss-6212b5c2848e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*Gqfoe4unrstntb8VV0f_EQ.jpeg</url>
            <title>Stories by Mark Sauer-Utley on Medium</title>
            <link>https://medium.com/@mark.utley.713?source=rss-6212b5c2848e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 05:15:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mark.utley.713/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Accessible Art Direction with Gatsby Images and React Hooks]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://javascript.plainenglish.io/accessible-art-direction-with-gatbsy-images-600b7b23eca8?source=rss-6212b5c2848e------2"><img src="https://cdn-images-1.medium.com/max/2600/1*cDu88cs688fNv0dhfA1ETA.jpeg" width="6000"></a></p><p class="medium-feed-snippet">I recently gave a talk at the GatsbyNYC meetup about doing art direction with images in Gatsby.</p><p class="medium-feed-link"><a href="https://javascript.plainenglish.io/accessible-art-direction-with-gatbsy-images-600b7b23eca8?source=rss-6212b5c2848e------2">Continue reading on JavaScript in Plain English »</a></p></div>]]></description>
            <link>https://javascript.plainenglish.io/accessible-art-direction-with-gatbsy-images-600b7b23eca8?source=rss-6212b5c2848e------2</link>
            <guid isPermaLink="false">https://medium.com/p/600b7b23eca8</guid>
            <category><![CDATA[gatsbyjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[accessibility]]></category>
            <dc:creator><![CDATA[Mark Sauer-Utley]]></dc:creator>
            <pubDate>Sat, 07 Mar 2020 22:47:59 GMT</pubDate>
            <atom:updated>2020-03-09T08:06:34.806Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Updating ApolloClient cache and re-rendering data]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/data-science/updating-apolloclient-cache-and-re-rendering-data-4537c11c6daf?source=rss-6212b5c2848e------2"><img src="https://cdn-images-1.medium.com/max/600/1*z-LROfr9BoiuMhlra-_OZQ.png" width="600"></a></p><p class="medium-feed-snippet">One of the nicest things about using ApolloClient is the automatic in-memory caching you get out of the box. When paginating your data&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/data-science/updating-apolloclient-cache-and-re-rendering-data-4537c11c6daf?source=rss-6212b5c2848e------2">Continue reading on TDS Archive »</a></p></div>]]></description>
            <link>https://medium.com/data-science/updating-apolloclient-cache-and-re-rendering-data-4537c11c6daf?source=rss-6212b5c2848e------2</link>
            <guid isPermaLink="false">https://medium.com/p/4537c11c6daf</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[apollo-client]]></category>
            <dc:creator><![CDATA[Mark Sauer-Utley]]></dc:creator>
            <pubDate>Sat, 19 Oct 2019 20:31:43 GMT</pubDate>
            <atom:updated>2019-11-01T11:54:03.428Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Creating a dark mode for your React app with useContext()]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/swlh/creating-a-dark-mode-for-your-react-app-with-usecontext-65c408a3b8e8?source=rss-6212b5c2848e------2"><img src="https://cdn-images-1.medium.com/max/1186/1*7PVKmF9yQLGtA0PsY3a3yA.png" width="1186"></a></p><p class="medium-feed-snippet">I&#x2019;m a huge fan of dark mode. I have dark themes for everything on my mac: VSCode, Chrome, Alfred, all of it. My background on my desktop&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/swlh/creating-a-dark-mode-for-your-react-app-with-usecontext-65c408a3b8e8?source=rss-6212b5c2848e------2">Continue reading on The Startup »</a></p></div>]]></description>
            <link>https://medium.com/swlh/creating-a-dark-mode-for-your-react-app-with-usecontext-65c408a3b8e8?source=rss-6212b5c2848e------2</link>
            <guid isPermaLink="false">https://medium.com/p/65c408a3b8e8</guid>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Mark Sauer-Utley]]></dc:creator>
            <pubDate>Fri, 14 Jun 2019 01:38:17 GMT</pubDate>
            <atom:updated>2019-07-29T23:44:54.251Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Lessons I learned from music that helped me learn to code]]></title>
            <link>https://medium.com/@mark.utley.713/stuff-i-learned-from-music-that-helps-me-code-d2a73a583173?source=rss-6212b5c2848e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2a73a583173</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <dc:creator><![CDATA[Mark Sauer-Utley]]></dc:creator>
            <pubDate>Sun, 04 Nov 2018 17:49:26 GMT</pubDate>
            <atom:updated>2018-11-04T18:28:16.542Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*oq-q8fA9yMyKDcbItphMsA.jpeg" /><figcaption>some music I once played</figcaption></figure><p>My background is primarily in music. I went to music school a couple of times and got a couple of degrees in “Percussion Performance and Literature.” Basically, I learned to play a lot of instruments that involve some form of hitting and spent a lot of time hitting them.</p><p>As I have made the career change from musician to programmer, I have realized that a ton of what I learned from music has helped me achieve my goals in programming. So here’s some stuff I learned in music that I have found useful.</p><h4>How to suck at something</h4><p>Whenever I started learning a new piece of music or playing a new instrument, I inevitably sucked at it. A huge part of being a musician was being okay with sucking at new things and figuring out what to do to not suck anymore.</p><p>Maybe the piece of music was too fast and I needed to spend a few days building up speed. Maybe I didn’t have the necessary physical stamina and needed to spend a few hours every day just playing exercises to build my chops. Maybe the rhythms were difficult and I needed to play the piece at a slower tempo until I really had them in my bones. Whatever the thing I sucked at was, I knew there was a way I could make myself not suck at it. It just took a little (or a lot of) work.</p><p>I have found the same to be true of coding. When I started learning javascript, I would spend hours debugging very simple things, because I sucked at it. I didn’t have a good grasp of the syntax and had no clue what “best practices” were. But I was fine with it, because I knew that if I could isolate my weaknesses, I could learn to turn them into strengths.</p><p>When I sucked at basic stuff like loops, I wrote tons of for-loops that did all sorts of random and useless things. I just needed to understand how to write a for-loop. When I started trying to learn algorithms, I realized that if I could tell someone else how to do them, then I would not suck at them anymore. So I wrote blog posts about <a href="https://medium.com/@mark.utley.713/heapsort-for-javascript-newbies-598d25477d55">heapsort</a>, <a href="https://medium.com/@mark.utley.713/a-sort-of-quick-guide-to-quicksort-and-hoares-partitioning-scheme-in-javascript-7792112c6d1">quicksort</a>, and <a href="https://medium.com/@mark.utley.713/insertion-sort-for-javascript-newbies-2091632fa104">insertion sort</a>.</p><p>All of this requires a period of sucking though. And it was super important for me to not get discouraged during that period.</p><h4>How to break down a problem</h4><p>The specific kind of music I played has a few names like “contemporary classical” or “new music.” The defining feature of this scene is that there are composers who write new music for performers to play. Sometimes, these composers write for instruments that have to be built by the performer (<a href="https://www.youtube.com/watch?v=00gisdkNSTE">here</a> is a little clip of one of my groups playing instruments we built out of 2x4’s). Other times, they write new ways of playing an instrument. Whatever the piece, there was always a new problem to solve.</p><p>In almost every case, that problem could be broken down into sub-problems. For our 2x4 music, one of the main problems was “how do you make a 2x4 sound good?” We can break this down into five sub-problems to solve.</p><ul><li>Decide what wood sounds best based on its density and hardness (we use pine)</li><li>Figure out how best to suspend the wood so it can resonate (we built sawhorses with special felt holders)</li><li>Figure out the right mallets to hit it with (we use rubber)</li><li>Decide how to amplify it (we use contact microphones)</li><li>Find the best mix (we crank the bass)</li></ul><p>I have found that this process is incredibly useful in programming as well. When I was at the Flatiron School, a friend and I built a web app that controls playback for your Spotify devices with your voice. It was quite an undertaking for students of our experience level, but each subproblem was pretty doable.</p><ul><li>Get an OAuth strategy working for Spotify</li><li>Write some code that makes requests to the Spotify Connect Web API</li><li>Use Artyom.js to parse speech to text</li><li>Build command functions to trigger with Artyom</li></ul><p>And of course, each of these could be broken down into further sub-problems. The main point is that no matter how daunting a task, you can break it down into smaller, digestible chunks and solve them one at a time.</p><h4>How to learn from mistakes</h4><p>There are few worse feelings than making a huge mistake in an orchestra rehearsal in front of 60 of your colleagues. If you are a percussionist, there is a good chance your mistake was very loud and everyone heard it. There is also a good chance the conductor is going to stop and call you out in front of everyone, furthering the humiliation.</p><p>In this situation (one in which I found myself countless times because you are bound to make mistakes as a student), I found that the best solution was always to say “sorry”, write a big note to yourself in your music, and don’t make that mistake again. Being able to recover from mistakes and correct them in the future has helped me a ton in learning to program.</p><p>The most important step in this is always understanding <strong><em>why</em></strong> I made the mistake in the first place. Was it because I hadn’t spent enough time practicing? Was it because I didn’t understand what some Italian word meant in my music? Was it because I didn’t listen to the piece enough beforehand to know what it sounds like?</p><p>It’s the same with coding. Did I have a bug because I didn’t understand how accumulators work in Array.prototype.reduce()? Or did I misunderstand how variables are passed by value vs. passed by reference? If I can identify why I made the mistake, I can resolve the underlying issue.</p><p>The nice thing about this approach is that you are proactively preventing yourself from future mistakes that would have stemmed from the same issue. And since programmers are lazy, killing many birds with one stone is a nice deal.</p><h4>How to handle critiques</h4><p>When you are in music school, you have a “primary teacher.” This is someone you study your main instrument with for the entirety of your degree program. They are essentially your mentor, often offering life and career advice along with teachings on how to not suck at music.</p><p>For music students who want to get the most out of their teacher, it is important to remember that they make critiques for your benefit and not to make you feel bad. It is tempting to make excuses or even to argue when they tell you that you did something wrong, but it is not productive. What’s productive is being receptive to feedback and spending time implementing those suggestions.</p><p>I have found this same approach to be beneficial when working with mentors or instructors in programming. At the Flatiron School, I found that I learned and solved problems much more quickly the more I implemented my instructors lessons and critiques. Wild how that works, huh?</p><p>I know this sounds super obvious, but I have found that it is actually something that takes constant practice and mental reminders. It’s super easy to forget in the moment when you feel bad for making a mistake. But being receptive to feedback has helped me make a ton of progress on the code road.</p><h4>Bye</h4><p>That’s all I got for now. Hope you enjoyed reading this and that maybe you can find some bit of my experiences relevant to your own :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2a73a583173" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A guide to const, let, and var for those of us who still might be confused]]></title>
            <link>https://medium.com/@mark.utley.713/a-guide-to-const-let-and-var-for-those-of-us-who-still-might-be-confused-1fc68eb5ff32?source=rss-6212b5c2848e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fc68eb5ff32</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Mark Sauer-Utley]]></dc:creator>
            <pubDate>Sat, 27 Oct 2018 08:09:37 GMT</pubDate>
            <atom:updated>2018-11-07T17:08:43.063Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*c5ph74BEv9A9ds7rq9ukCQ.png" /><figcaption>Constants are mutable?!</figcaption></figure><p>I really like Javascript. I like reading about it, writing about it, and most of all, coding in it. I am a coding bootcamp graduate and until recently, I have only ever worked with client-side Javascript, doing all of my server-side coding in Ruby. I wanted to extend my knowledge of JS so I purchased a great Node.js course on Udemy and have been working my way towards building full-stack JS applications.</p><p>Something I have noticed from questions I get about my blog posts and even from the instruction in this Node course is that a ton of people are still hazy on the differences between let, var, and const. So I wanted to do a short post about the differences between them and my personal strategy for choosing which to use.</p><h4>Const and block-scoping</h4><p>This seems to be the one that I get the most questions about. A lot of people think that const has global scope no matter where it is declared. This is not true! Just like let, const is block-scoped.</p><p>What does this mean? This means that variables declared with const are only available in the scope of the block in which they are declared. I know that definition sucks, but think of it like this:</p><p>If you declare a const inside of a function or if-statement, you can declare a const with the same name inside another block without getting an error. Think of a block as the code chunks between curly-braces (the exceptions being objects and maps). This will work:</p><pre>function someFunc() {<br>  const hello = &quot;hello&quot;;<br>  return hello;<br>}</pre><pre>if (1 === 1) {<br>  const hello = &quot;hello again&quot;;<br>} else {<br>  const hello = &quot;hi there&quot;;<br>}</pre><p>Each of these hello variables are locally-scoped to the block in which they are declared. So the only places they are available are between the curly braces that surround them. You will not be able to access them in the global scope. So this will NOT work:</p><pre>function someFunc() {<br>  const hello = &quot;hello&quot;;<br>  return hello;<br>}</pre><pre>if (1 === 1) {<br>  const hello = &quot;hello again&quot;;<br>} else {<br>  const hello = &quot;hi there&quot;;<br>}</pre><pre>console.log(hello);</pre><pre>// ReferenceError: hello is not defined</pre><p>The console.log breaks, because there is no hello variable in that scope.</p><p>You cannot, however redeclare a const in the same block in which it is declared. So this will break:</p><pre>const hello = &quot;hello&quot;;<br>const hello = &quot;hi there!&quot;;</pre><pre>// SyntaxError: Identifier &#39;hello&#39; has already been declared</pre><p>Now remember, the typical rules of scope still apply and child scopes will still inherit the scope of their parent. So this will also work:</p><pre>function parentFunc() {<br>  const hello = &quot;hello, how are you&quot;;<br>  <br>  return function(name) {<br>    return `${hello} `${name}?`;<br>  }<br>}</pre><pre>parentFunc()(&quot;Mark&quot;);</pre><pre>// =&gt; &quot;hello, how are you Mark?&quot; </pre><p>As will this:</p><pre>function someFunc(name) {<br>  const hello = &quot;hello&quot;;</pre><pre>  if (name === &quot;Mark&quot;) {<br>    return `hey ${name}.`;<br>  } else {<br>    return `${hello} ${name}!`;<br>  }<br>}</pre><pre>someFunc(&quot;Jamie&quot;);</pre><pre>// =&gt; &quot;hello Jamie!&quot;</pre><p>In both cases, hello is scoped within the block it is declared and therefore available within any scopes that are children of that block.</p><p>But wait! This part is super important. Block-scoped variables<strong> <em>can be redeclared in child scopes without breaking</em>.</strong> This may seem counter intuitive, but this is perfectly valid code:</p><pre>function someFunc() {<br>  const hello = &quot;hello&quot;;</pre><pre>  if (true) {<br>    const hello = &quot;hi!&quot;;<br>    console.log(hello);<br>  }<br>  console.log(hello);<br>}</pre><pre>// &quot;hi!&quot;<br>// &quot;hello&quot;</pre><p>When a const is declared in a child scope, JS looks for a variable with the same name in that block first. If it doesn’t find one, the variable is created in that block and for that scope.</p><p>When the const is referenced, the JS engine will look in the current scope, then to the parent, and so-on up the scope chain until it finds what it is looking for. So if it finds one in the current scope, it stops looking. That’s why this does not break.</p><p>So that’s block scoping! Both const and let are block-scoped, which is important to remember for later. But first, I want to go over what makes const unique.</p><h4>Const and reassignment</h4><p>What makes const different from let is that it cannot be reassigned. A const must be defined when it is declared, unlike let or var. So const must always be declared like this:</p><pre>const hello = &quot;hello&quot;;</pre><p>Not like this:</p><pre>const hello;<br>hello = &quot;hello&quot;;</pre><pre>// SyntaxError: Missing initializer in const declaration</pre><p>What this also means is that a variable declared with const must always point to the same place in memory.</p><p>Note that this does not mean that the data it points to is immutable! It is super mutable. Piscean even. You can manipulate an object all day and it will still be the same object. So this will work:</p><pre>const person = { name: &quot;Mark&quot; };<br>person.age = 27;<br>person.favoriteColor = &quot;green&quot;;</pre><p>This is also fine:</p><pre>const people = [&quot;Mark&quot;, &quot;Naomi&quot;, &quot;Carol&quot;, &quot;Jordan&quot;];<br>people.pop();<br>people.push(&quot;Tristan&quot;);</pre><p>But this is not fine:</p><pre>const counter = 0;<br>counter++;</pre><p>Because it is the same as this:</p><pre>const counter = 0;<br>counter = counter + 1;</pre><p>…which is reassigning the variable. You are not mutating 0 here, because 0 is always 0. You are telling counter to point to the integer 1, AKA reassigning it. Numbers are not mutable data!</p><h4>Let</h4><p>We said earlier that let is also block-scoped. So all the same rules about scoping for const apply to let. What makes them different is that let can be reassigned.</p><p>So this works:</p><pre>let hello;</pre><pre>if (true) {<br>  hello = &quot;hello&quot;;<br>} else {<br>  hello = &quot;goodbye&quot;;<br>}</pre><pre>console.log(hello);</pre><pre>// &quot;hello&quot;</pre><p>As does this:</p><pre>let counter = 0;<br>counter++;</pre><pre>console.log(counter);</pre><pre>// 1</pre><p>It’s also a great choice for for-loop iterators:</p><pre>const array = [1, 2, 3, 4, 5];</pre><pre>for (let i = 0; i &lt; array.length; i++) {<br>  console.log(array[i]);<br>}</pre><pre>// 1<br>// 2<br>// 3<br>// 4<br>// 5</pre><p>They cannot, however, be re-declared! This will break:</p><pre>let hello = &quot;hello&quot;;<br>let hello = &quot;hi there!&quot;;</pre><pre>// SyntaxError: Identifier &#39;hello&#39; has already been declared</pre><p>But, since they are block-scoped like const, this will still work:</p><pre>function someFunc() {<br>  let hello = &quot;hello&quot;;</pre><pre>  if (true) {<br>    let hello = &quot;hi!&quot;;<br>    console.log(hello);<br>  }<br>  console.log(hello);<br>}</pre><pre>// &quot;hi!&quot;<br>// &quot;hello&quot;</pre><h4>Var and function scoping</h4><p>The biggest difference between let and var is the way they are scoped. So we know let and const are scoped by block, whether that block be part of a function or a statement.</p><p>var on the other hand, is function-scoped. This means that variables declared with var are scoped according to their current execution context. Variables that are declared outside of a <strong>function</strong> are <strong>globally-scoped</strong><em>.</em></p><p>Take a look here:</p><pre>var hello = &quot;hello&quot;;</pre><pre>if (true) {<br>  var hello = &quot;goodbye&quot;;<br>}</pre><pre>console.log(hello);</pre><pre>// &quot;goodbye&quot;;</pre><p>Now look at what happens when it is declared inside a function:</p><pre>var hello = &quot;hello&quot;;</pre><pre>function someFunc() {<br>  var hello = &quot;goodbye&quot;;<br>  console.log(hello);<br>}</pre><pre>someFunc();<br>console.log(hello);</pre><pre>// &quot;goodbye&quot;;<br>// &quot;hello&quot;;</pre><p>The same rules about scope inheritance and the scope chain apply here, but only in the context of functions. Variables declared with var inside if-else statements or as iterators in for-loops are hoisted to the global scope (or, if that statement is inside a function, they are hoisted to the scope of the function) and available throughout the rest of the application.</p><p>So if you use var in a for loop, you get some weird stuff:</p><pre>var array = [1, 2, 3, 4, 5];<br>var i = 0;</pre><pre>for (var i = 0; i &lt; array.length; i++) {<br>  console.log(array[i]);<br>}</pre><pre>console.log(i);</pre><pre>// 1<br>// 2<br>// 3<br>// 4<br>// 5<br>// 5</pre><p>On the last line, console.log(i), the value of i is 5, because the i in the for-loop is scoped globally.</p><p>Let’s see what happens when we do the same for-loop using let:</p><pre>let array = [1, 2, 3, 4, 5];<br>let i = 0;</pre><pre>for (let i = 0; i &lt; array.length; i++) {<br>  console.log(array[i]);<br>}</pre><pre>console.log(i);</pre><pre>// 1<br>// 2<br>// 3<br>// 4<br>// 5<br>// 0</pre><p>There we go, now our for-loop doesn’t have any side-effects.</p><p>Lastly, var can be redeclared. So this will not break:</p><pre>var hello = &quot;hello&quot;;<br>var hello = &quot;goodbye&quot;;</pre><p>This is not ideal, as you probably don’t want to redeclare variables. If you need a new variable, you should use a new variable name to avoid weird side-effects and the like. Of course you would never redeclare a variable on the next line as I have above, but you (or a coworker working on the same repo) might create a variable with the same name in a block somewhere 100 lines down and not notice.</p><p><em>Note: you can avoid this with “use strict” and many people did that for a long time. But now we have let and const to fix this problem.</em></p><h4>Opinion time</h4><p>So you may be thinking, “okay how do I know which one to use?” Well, here is my strategy. Not to say it is the only right way to go, but it has worked for me so far.</p><p>I never use var. I have never needed to. There might be some case where you need your variables hoisted out of your blocks, but I imagine that if that is the case, you can just refactor your code. The problem with var is that it can easily produce unintended side-effects. If you use var in a block and maybe your coworker doesn’t realize it, they might try to use the same variable name somewhere else and the result will be unexpected behavior.</p><p>Instead, I always declare my variables with const unless I know they need to be reassigned (like counters or iterators). If that is the case, I use let and know that it will only be available in the scope of that block and there will be no global side-effects. This can save you a ton of debugging confusion down the road and helps your coworkers read your code.</p><p>If you had any questions about var, let, or const, hopefully this helped! Thank you for reading!</p><figure><a href="https://blog.usejournal.com/meet-journal-d222fce8db1d"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2IVAl0TbsfES9cFGYr40g.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fc68eb5ff32" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A sort of quick guide to quicksort and Hoare’s partitioning scheme in Javascript]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://itnext.io/a-sort-of-quick-guide-to-quicksort-and-hoares-partitioning-scheme-in-javascript-7792112c6d1?source=rss-6212b5c2848e------2"><img src="https://cdn-images-1.medium.com/max/1166/1*XWPlyIpaqlh7WqXQ_3BZNg.png" width="1166"></a></p><p class="medium-feed-snippet">Today I&#x2019;m gonna talk about quicksort. Pretty exciting, right? I&#x2019;ve written in the past about implementing a very basic version of&#x2026;</p><p class="medium-feed-link"><a href="https://itnext.io/a-sort-of-quick-guide-to-quicksort-and-hoares-partitioning-scheme-in-javascript-7792112c6d1?source=rss-6212b5c2848e------2">Continue reading on ITNEXT »</a></p></div>]]></description>
            <link>https://itnext.io/a-sort-of-quick-guide-to-quicksort-and-hoares-partitioning-scheme-in-javascript-7792112c6d1?source=rss-6212b5c2848e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7792112c6d1</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Mark Sauer-Utley]]></dc:creator>
            <pubDate>Mon, 22 Oct 2018 03:10:34 GMT</pubDate>
            <atom:updated>2019-06-28T12:22:50.613Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[A wild way to check if a number is prime using a regular expression]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://itnext.io/a-wild-way-to-check-if-a-number-is-prime-using-a-regular-expression-4edfb725f895?source=rss-6212b5c2848e------2"><img src="https://cdn-images-1.medium.com/max/792/1*O_y3aI4bgyzgANxefGLf6Q.png" width="792"></a></p><p class="medium-feed-snippet">Somewhere, in all of your past googling of prime number algorithms, you might have come across something like this:</p><p class="medium-feed-link"><a href="https://itnext.io/a-wild-way-to-check-if-a-number-is-prime-using-a-regular-expression-4edfb725f895?source=rss-6212b5c2848e------2">Continue reading on ITNEXT »</a></p></div>]]></description>
            <link>https://itnext.io/a-wild-way-to-check-if-a-number-is-prime-using-a-regular-expression-4edfb725f895?source=rss-6212b5c2848e------2</link>
            <guid isPermaLink="false">https://medium.com/p/4edfb725f895</guid>
            <category><![CDATA[prime-numbers]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[regex]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Mark Sauer-Utley]]></dc:creator>
            <pubDate>Sat, 13 Oct 2018 21:31:06 GMT</pubDate>
            <atom:updated>2018-10-17T10:27:58.177Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Insertion Sort for Javascript Newbies]]></title>
            <link>https://medium.com/@mark.utley.713/insertion-sort-for-javascript-newbies-2091632fa104?source=rss-6212b5c2848e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2091632fa104</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[sorting-algorithms]]></category>
            <category><![CDATA[code-newbie]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Mark Sauer-Utley]]></dc:creator>
            <pubDate>Tue, 14 Aug 2018 11:42:50 GMT</pubDate>
            <atom:updated>2018-08-14T11:42:50.887Z</atom:updated>
            <content:encoded><![CDATA[<p>Today is all about insertion sort and implementing it in javascript! Insertion sort is, as you may have guessed, a sorting algorithm. It is fairly slow compared to more powerful sorting algorithms like heapsort, mergesort, and quicksort. That doesn’t mean it isn’t worth learning though. I am of the belief that building these things out and making your brain think about these puzzles can only make you a better coder.</p><p>If you are new to coding and want to learn some algorithms as a fun way to improve your skills, insertion sort is a great one to start with as the steps are pretty easy to follow along.</p><p>Great! So what is it?</p><h4>Steps</h4><p>Insertion sort works like this:</p><ol><li><em>For each item in a list</em></li><li><em>Compare it to the previous item. If the previous item is larger, swap it.</em></li><li><em>If you have swapped those two, continue swapping the larger element with the ones before it until it is in the right place.</em></li></ol><h4>Swapping</h4><p>Great! So let’s start with some array of jumbled numbers:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*OQ2ETrMT8SWdJHhoD-rapg.png" /></figure><p>What a mess. Someone better sort those numbers.</p><p>Okay so let’s look at step 1 again.</p><p><em>For each item in a list</em></p><p>Okay we can do that. That sounds like a for loop to me. There’s also a bit of a clue in step 2 about where to start. Step 2 says, “compare it to the previous item.” That tells me that our for loop is going to start iterating at index 1 and not index 0, because it needs a previous element to compare. Okay let’s get started!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*cUcjvi5HSBbHmO3z9D6q0g.png" /></figure><p>Great. We got the skeleton of our loop! Let’s look at step 2 again:</p><p><em>Compare it to the previous item. If the previous item is larger, swap it.</em></p><p>Okay! Let’s do that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2-Qlh8mG9pbVqL7YmSksaQ.png" /></figure><p>Woah we are seriously nailing this. Great job everyone. Okay next step!</p><p><em>If you have swapped those two, continue swapping the larger element with the ones before it until it is in the right place.</em></p><p>Hmm… okay. Well. I guess we could write another loop in that if statement? Maybe another for loop that loops backwards starting at index i and goes back to the beginning?</p><p>Yes, we could do that. We could do a lot of things. But should we?</p><p>To me, this step has some clues as to what we should do. The step is structured as if-something-then-something (it doesn’t say “then” anywhere, but “then” is implicit because English is weird). This sounds like a great base case for a recursive function. If we call a recursive function inside that for loop, it can handle recursively calling itself as needed, saving us the trouble of writing tricky nested loops but achieving the same behavior.</p><p>So what does that look like? Well let’s back up and look at those steps again.</p><ol><li><em>For each item in a list</em></li><li><em>Compare it to the previous item. If the previous item is larger, swap it.</em></li><li><em>If you have swapped those two, continue swapping the larger element with the ones before it until it is in the right place.</em></li></ol><p>So this code is covering step one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*cUcjvi5HSBbHmO3z9D6q0g.png" /></figure><p>Now let’s go ahead and build a helper function that takes in an index and an array as its arguments. It will handle the checking and swapping involved in step 2 by comparing the element at the index passed in with the previous element:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*OkWzTar8QWSiKE6_C5xOxQ.png" /></figure><p>Okay. Why did we do this?</p><p>Well now, we can make checkAndSwap() recursive, using the if statement on line 8 as our base case, and passing in i — 1 as the index to check. Let’s see that!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*37_IuE0lIRLYsgL-IUADPQ.png" /></figure><p>So now checkAndSwap() will call itself recursively until the element at the index passed into it is in its right place. So we’ve solved the problem of having to write messy nested loops on line 3. Again, you can do it that way, but I personally have a really hard time reading code like that. I like everything to have an easy flow of logic that I can follow by just reading the code, and nested loops with multiple iterator variables and tons of if statements make my brain hurt.</p><p>Okay cool so now we just have to call this function inside of that for loop!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*dY3nH12crkBVStUUhrOn4g.png" /></figure><p>Cool! Now let’s look at our array from the beginning:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*OQ2ETrMT8SWdJHhoD-rapg.png" /></figure><p>Our for loop is going to start by calling checkAndSwap() on arr[1]. It will see that 5 is larger than 3 and do nothing to our array, sending it back to the next iteration of our for loop.</p><p>Next our for loop will have i = 2 and will call checkAndSwap() on arr[2]. So now we are comparing 2 and 5 in our array. The if statement on line 8 will evaluate to true and the block of code below will execute, swapping the 5 and the 2 and calling checkAndSwap() again on arr[1]. Before the recursive call happens on line 10, our array looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*d2pqiXjfhu16CUGIVeE2iA.png" /></figure><p>2 and 5 swapped places, which is great! But see how 2 isn’t done swapping? It needs to swap with 3 now to be in its proper place. This is why have the recursive call on line 10 in our code!</p><p>Let’s take one last look at our steps:</p><ol><li><em>For each item in a list</em></li><li><em>Compare it to the previous item. If the previous item is larger, swap it.</em></li><li><em>If you have swapped those two, continue swapping the larger element with the ones before it until it is in the right place.</em></li></ol><p>Looks like we got all those bases covered, right? I guess all that is left is to return our array! This is a very easy step, but one that many newbies get stuck on. When I first started learning javascript, I would spend hours debugging code that was doing exactly what I needed it to, with the exception that I forgot to return something from my function. So remember, always return the thing you need!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*NffhsXttPll1no6fhqcE6w.png" /></figure><h4>A Note on Pure Functions and Return Values</h4><p>checkAndSwap() does not need to return anything because insertion sort sorts arrays in place, meaning it operates on the original array rather than making a copy that is a sorted version of the array. Since we don’t need a return value from checkAndSwap(), we don’t have to write a return statement.</p><p>For those of you following along with programming paradigms in mind, this means that insertion sort does not fit into the functional programming paradigm because it is mutating our original data. A big clue that a function is not pure (i.e. it has the side-effect of mutating our original data) is if it makes sense for the function to not have a return value.</p><h4>Wrapping Up</h4><p>I hope you enjoyed learning insertion sort with me! If you want more content like this, check out my posts <a href="https://medium.com/@mark.utley.713/heapsort-for-javascript-newbies-598d25477d55">Heapsort for Javascript Newbies</a> and <a href="https://medium.com/@mark.utley.713/beginner-rubyists-guide-to-quicksort-d109fac9e6d8">Beginner Rubyist’s Guide to Quicksort</a>.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2091632fa104" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Heapsort for Javascript Newbies]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://levelup.gitconnected.com/heapsort-for-javascript-newbies-598d25477d55?source=rss-6212b5c2848e------2"><img src="https://cdn-images-1.medium.com/max/852/1*0isybKjBzHgqvVgv--Wxhg.png" width="852"></a></p><p class="medium-feed-snippet">Get ready to rage because today we&#x2019;re talking about heapsort! I&#x2019;m going to walk through this algorithm with you step-by-step in a&#x2026;</p><p class="medium-feed-link"><a href="https://levelup.gitconnected.com/heapsort-for-javascript-newbies-598d25477d55?source=rss-6212b5c2848e------2">Continue reading on Level Up Coding »</a></p></div>]]></description>
            <link>https://levelup.gitconnected.com/heapsort-for-javascript-newbies-598d25477d55?source=rss-6212b5c2848e------2</link>
            <guid isPermaLink="false">https://medium.com/p/598d25477d55</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[sorting-algorithms]]></category>
            <dc:creator><![CDATA[Mark Sauer-Utley]]></dc:creator>
            <pubDate>Thu, 26 Jul 2018 13:03:47 GMT</pubDate>
            <atom:updated>2019-09-04T14:21:33.450Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Memoization in Ruby]]></title>
            <link>https://medium.com/@mark.utley.713/memoization-in-ruby-87261f7e7c9a?source=rss-6212b5c2848e------2</link>
            <guid isPermaLink="false">https://medium.com/p/87261f7e7c9a</guid>
            <category><![CDATA[dynamic-programming]]></category>
            <category><![CDATA[memoization]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Mark Sauer-Utley]]></dc:creator>
            <pubDate>Sun, 01 Jul 2018 13:17:39 GMT</pubDate>
            <atom:updated>2018-07-02T13:08:09.200Z</atom:updated>
            <content:encoded><![CDATA[<p>You know those things that you learn and then think, “Oh that should have been so obvious. Why did I not just know to do that already?”</p><p>Memoization was one of those things for me. It is such a simple solution to a problem that comes up quite often (so often in fact that rails has a built in memoize module). It’s a really good tool to know about and know when to use it. So here we’re going to look at 1) what memoization is, 2) a simple problem that can be solved <em>without</em> memoization, and 3) how that problem is better solved <em>with</em> memoization. Okay let’s go!</p><h4><strong>Primer</strong></h4><p>Before we talk about memoization, I want to first bring up Dynamic Programming. Dynamic Programming (or “DP”) is an optimization technique that breaks a problem up into smaller sub-problems in a recursive manner. This basically means that we are making our workload modular, assembling the smaller pieces we have solved into larger solutions. If you want to take a deeper dive on DP, check out the plethora of resources <a href="https://www.geeksforgeeks.org/dynamic-programming/">here on Geeks for Geeks.</a></p><p>Memoization is a technique that is used <em>in</em> DP (but not always). The two are not synonymous, but being familiar with the concepts of DP will help you understand memoization and when you should and shouldn’t use it.</p><h4><strong>So what is Memoization?</strong></h4><blockquote>In computing, <strong>memoization</strong> or memoisation is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again.</blockquote><blockquote>-Wikipedia</blockquote><p>You know when you have a good idea and want to write it down so you don’t forget it? Or maybe you cook something real good and write down the recipe so you can make that same thing agin? That’s basically what memoization is. Our program does some work and then says, “jeeze that sucked. I don’t want to have to do that again. I’m gonna write that down real quick.” That way, when you need the return value from that method again, it’s right there waiting for you and you don’t have to repeat all the steps in your method to get it.</p><h4>So let’s see an example, already!</h4><p>Okay!</p><p>Let’s say we have to build a function called fibonacci that calculates numbers in a fibonacci sequence starting at 0.</p><p>So our fibonacci sequence would look like this:</p><pre>[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 etc...]</pre><p>Our function will take an input of a number called num and return the fibonacci number at that index in the sequence. So our fibonacci numbers with their indexes num would look like this:</p><pre>num =  0  1  2  3  4  5  6  7   8   9   10<br>fib = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 etc...]</pre><p>And our function inputs and outputs will look like this:</p><pre>fibonacci(0) = 0<br>fibonacci(1) = 1<br>fibonacci(2) = 1<br>fibonacci(3) = 2<br>fibonacci(4) = 3<br>fibonacci(5) = 5<br>fibonacci(6) = 8<br>etc...</pre><h4>Building the method</h4><p>Let’s start by doing this a silly way without memoization.</p><p>Since any fibonacci number is the sum of the two preceding fibonacci numbers, then it is safe to say:</p><pre>fibonacci(num) = fibonacci(num - 1) + fibonacci(num - 2)</pre><p>I don’t know about you, but that looks like recursion to me. To create a naive solution to this problem, all we would have to do is throw on a base case and we can get the party started. Since we know the first number in our sequence (index 0) is 0 and the second (index 1) is 1, we can use those as our base case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*FLoZW6aVMBpzWdatLG3_PQ.png" /></figure><p>This will work, but we are doing something super silly. Do you see it? We are calling fibonacci(num — 1) on the left side of line 3, which is going to be...</p><p>fibonacci(num — 1) = fibonacci(num — 2) + fibonacci(num — 3)</p><p>But we are also calling fibonacci(num — 2) on the right side of line 3, which means we are doing that recursive call TWICE. That sucks. Let’s see what happens when we look for fibonacci(6), which is the number 8:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eTERQNSSTao8o58hb4KdWw.jpeg" /></figure><p>As you can see, we are calculatingfibonacci(4) (which is the number 3) twice, which means we are calculating fibonacci(3) (the number 2) three times! That’s ridiculous!</p><p>Imagine we needed to find fibonacci(3000) . Our program would be unbelievably inefficient if it had to calculate all the way down to fibonacci(1) for every recursive call.</p><h4>Well what can we do about it?</h4><p>Enter memoization.</p><p>Remember when we said that memoization is a technique that <strong>stores computed values </strong>to avoid duplicated work? That sounds real useful right about now.</p><p>So let’s start by setting up a hash.</p><pre>Fibs = {}</pre><p>The keys of our hash will be the indexes in the fibonacci sequence and the values will be the numbers at those indexes. So…</p><pre>Fibs[0] = 0<br>Fibs[1] = 1<br>Fibs[2] = 1<br>Fibs[3] = 2<br>Fibs[4] = 3<br>etc...</pre><p>Our method that uses memoization will start the same as our silly method that did not:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*n_ejxnascLcNNWMk6eqWsA.png" /></figure><p>But now we can add another base case to stop all those repeated calls. Before we do any calculations, we are going to check and see if the answer we want is already in our Fibs hash, and return it if it is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*HAp9uK_mkjeLcSa3hCBcoA.png" /></figure><p>Now that we have this nifty base case, we can set up our recursive calls just like before, only this time we are going to put their return values into Fibs .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iIAF1j-Ss50uFdK6v5yymA.png" /></figure><p>So now, every one of those recursive calls is going check and see if fibonacci has already been called with that input, which means it will NEVER perform the same calculation twice. Rad, right?!</p><p>All we need to do now is return our fibonacci number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V7f0sscbKi228PVl2C6H3A.png" /></figure><h4>Are you sure this is better?</h4><p>If you don’t believe me, let’s take a look at our tree from earlier, and see what it looks like now with memoization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EpMJN7Sa0SZu1iwxDV5O9A.jpeg" /></figure><p>As you can see, we are now only finding each value once, whereas before we were recursively finding several of them multiple times.</p><p>Once we start looking for those larger fibonacci numbers, the work we are saving ourselves is really going to add up and increase the performance of our program.</p><p>Cool right?!</p><h4>Great! This will really help with all those fibonacci numbers I need in my web app…</h4><p>Oh you jokester.</p><p>This may seem like a useless thing here, but memoization is a great tool to have on hand. If you don’t believe me, check out <a href="http://gavinmiller.io/2013/basics-of-ruby-memoization/">this great article from Gavin Miller</a> on how you can use memoization to increase the performance of your rails apps.</p><p>Thanks for reading! I hope I have been able to adequately communicate the value of this technique and that you feel ready to go if into the world ready to memoize. If not, feel free to hit me up with any questions :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87261f7e7c9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>