<?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 Steph Wong on Medium]]></title>
        <description><![CDATA[Stories by Steph Wong on Medium]]></description>
        <link>https://medium.com/@stephaniewo?source=rss-604827d75d18------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uFa2BSueWYp5YX6eb3ncrg.jpeg</url>
            <title>Stories by Steph Wong on Medium</title>
            <link>https://medium.com/@stephaniewo?source=rss-604827d75d18------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 20:17:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stephaniewo/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[Strengthening Your Engineering Team With Pair Programming]]></title>
            <link>https://medium.com/levers-fulcrum/strengthening-your-engineering-team-with-pair-programming-809cd5e5ca1f?source=rss-604827d75d18------2</link>
            <guid isPermaLink="false">https://medium.com/p/809cd5e5ca1f</guid>
            <category><![CDATA[engineering-culture]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[pair-programming]]></category>
            <dc:creator><![CDATA[Steph Wong]]></dc:creator>
            <pubDate>Thu, 30 Jan 2020 19:41:33 GMT</pubDate>
            <atom:updated>2020-03-06T22:06:09.805Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Two of our engineers during a pairing session" src="https://cdn-images-1.medium.com/max/1024/1*bXB29Q49Xbn842dn4B50Zw.jpeg" /><figcaption>Two of our engineers during a pairing session</figcaption></figure><p>It’s easy to see why people would assume that programming is an individual activity–you can usually find each engineer sitting in front of their own computer, head-phoned up. But now that I’ve been at Lever for more than a year, it has shown me that programming can actually be a team sport! Through pair programming, engineering teams can help each other gain skills, grow knowledge of their systems, and build trust between its members.</p><h3>How Do You Encourage Pairing?</h3><p>When on-boarding as an engineer at Lever, you’ll already have pairing sessions scheduled on your calendar. It’s a great way to help introduce the codebase and we also want you to know that pairing is a strong part of our culture!</p><p>Pairing has the potential to help engineers in so many ways, so a lot of effort has been put in to ensure we get the most out of pairing at Lever. When we decided to make pairing a fundamental part of our engineering culture, we created two designated stations for pairing and formalized pairing guidelines–which are displayed above each station. Our two dedicated pairing stations are in rooms separate from the normal engineering seating area, so the engineers who are pairing can collaborate without interruptions. We wanted to communicate that pairing is valued and important for our team, so we were intentional about establishing these norms for pairing. By creating a designated space and giving engineers agency to make the most of their pairing session, our team became more inclined to set up sessions with each other.</p><figure><img alt="Lever’s pairing guidelines! We have our full version on Lever’s GitHub, but display a printed summary of key points" src="https://cdn-images-1.medium.com/max/971/0*5r1b0p0jbfKfoeJm" /><figcaption>Lever’s pairing guidelines! We have our full version on Lever’s GitHub, but display a printed summary of key points</figcaption></figure><p>Some key things these guidelines remind us to do with some example follow-up questions:</p><p><strong>Be aware of our headspace before pairing</strong></p><ul><li>Are you tired or hungry?</li><li>How long can you focus for?</li></ul><p><strong>Align expectations for how to prepare beforehand</strong></p><ul><li>What important product context do we need to reason about the solution?</li></ul><p><strong>Know what each person wants to get out of the pairing session</strong></p><ul><li>Do we want to brainstorm different solutions at a high level?</li><li>Is there an area of the codebase that’s unfamiliar and I want to know more about?</li><li>Is there a debugging technique I want to walk through?</li></ul><figure><img alt="A photo of one of our pairing stations!" src="https://cdn-images-1.medium.com/max/1024/1*tnMwEEh-NiB-mbSSStdKjg.jpeg" /><figcaption>One of our pairing stations</figcaption></figure><p>Senior engineers encourage pairing at Lever by holding open office hours. Typically an hour is blocked off on their calendar each week for others to book so that any engineering related questions can be addressed. This is helpful because some engineers may find it difficult to ask for help, since they may not want to take so much of another person’s time. But if there is time intentionally set aside for providing help, there’s less hesitation to ask questions! These office hours are really casual and easy to utilize. We just ping the engineer and ask about the availability that week and wait for the confirmation.</p><blockquote>“I enjoy collaborating on code, sharing creativity, and watching people grow over time with consistent pairing sessions.” — Leighton, Engineering Manager</blockquote><p>Another way pairing is encouraged and implemented at Lever is through pairs of engineers having recurring weekly pairing sessions. This way engineers don’t need to go through the hassle of scheduling every week and can plan ahead for each session. Even as our engineers grow, they continue these pairing sessions! By consistently working together, an engineer can help another pin-point weak spots and set specific goals to improve those areas over time. These goals can be more substantial than a goal for just a single pairing session. For example, instead of just figuring out how to write a unit test for a certain function, the goal could expand further on testing and focus on knowing what kind of test would be most effective, and understand for what reasons. It’s also really cool to see how much progress your teammates are making!</p><h3>We See the Impact of Pairing in So Many Ways</h3><figure><img alt="Two of our engineers talking through some code during a pairing session" src="https://cdn-images-1.medium.com/max/1024/1*dctslkImt8qdDRzWw7cyLw.jpeg" /><figcaption>Two of our engineers talking through some code during a pairing session</figcaption></figure><p>I can personally attest to the benefit of pairing! Before joining Lever, I worked in another field and decided to switch careers to doing engineering by completing a coding bootcamp. Coming from a bootcamp, I fell victim to some serious imposter syndrome. There was a lot of self-doubt and fear that I wasn’t qualified to be an engineer. I was constantly thinking, “What if I can’t learn fast enough? What if I don’t get it? Did I make a mistake changing careers?” But with each pairing session, I learned more about our tech stack, figured out best practices, picked up styling conventions, but most importantly, my confidence grew and I was able to squash those doubts. I want to share 3 impacts that pairing has had on me.</p><h4>Pairing Helps You Get to Know Your Teammates</h4><p>By pairing with different teammates, not only do you get to know others personally, you can also identify who is an expert in which parts of the code. With that information, you will be able to unblock yourself more efficiently because you know who to go to ask for help directly. You probably don’t regularly work with engineers from a different team either, so pairing sessions can also open doors to those opportunities.</p><blockquote>“You practice giving people feedback, learn other learning styles, and develop trust between other people.” — Zach, Senior Software Engineer</blockquote><p>Before knowing who the experts were, I might have had to talk to 2 people before getting to the right person who was best suited to help me. Now I know who I can ping directly, and unblock myself within the same day. Also, since I started pairing with engineers from other teams, I’ve been able to get a stronger sense of camaraderie throughout all of engineering!</p><h4>Pairing Can Optimize Your Workflow</h4><p>When pairing with other engineers, you can pick up tips and tricks for really owning your machine and being more efficient as an engineer. For example, how to use different features of Chrome DevTools, navigating your IDE more effectively, and even learning hot keys for the terminal. These are all little things other engineers have gained from trying different setups and configurations to optimize their workflow. Even though this information can be shared through documentation, the benefits of each practice is more impactful when demonstrated or learned through pairing.</p><p>Currently, as a junior engineer, one of the skills I’m working on is defining and validating problems. The debugging skills and advice for pinpointing a problem in our codebase I’ve gotten from pairing has really increased my rate of growth in this area. I’ve also discovered text-expanders, which allow you to create aliases for text snippets to be used in any interface one can type in.</p><h4>Pairing Provides Support and Can Solve Problems Faster</h4><p>Pairing with someone doesn’t mean one person needs to have all the answers. Sometimes, just having someone else there to give support can make the world of difference. By having another engineer to <a href="https://gitduck.com/blog/improve-how-to-code-with-rubber-duck-debugging/">rubber duck</a> with and give immediate feedback, you can spot bugs and resolve them faster than on your own.</p><blockquote>“It’s a good way to solve problems and one person is always learning”<br>- Jyrki, Senior Software Engineer</blockquote><p>When I got a calendar invite to pair with my team lead, my initial reaction was that I was invited by mistake. How could I, a junior engineer, help? Together, we stepped through different edge cases and narrowed down where the bug might have originated. This was a tedious manual process, but we were able to divide the work to complete it quicker. I also read through her code and tried to explain what I thought was happening. By doing this, we caught bugs and saw which lines were not as easily readable/understood.</p><h3>At Lever, We Love Pairing</h3><p>Not only has pair programming helped our engineers at Lever grow technically, the entire engineering team has become more cohesive, been able to onboard each other more quickly, and build trust between each other. With stronger bonds between all of us, we have the support needed to overcome any challenges that come with building a product that’s used by thousands. I’m so happy to be a part of a team where pairing is such a big part of the engineering culture. Thank you for pairing, Lever engineering!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=809cd5e5ca1f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/levers-fulcrum/strengthening-your-engineering-team-with-pair-programming-809cd5e5ca1f">Strengthening Your Engineering Team With Pair Programming</a> was originally published in <a href="https://medium.com/levers-fulcrum">Lever Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Inheritance and Composition in Ruby]]></title>
            <link>https://medium.com/entelo/understanding-inheritance-and-composition-in-ruby-edc46c0f96c7?source=rss-604827d75d18------2</link>
            <guid isPermaLink="false">https://medium.com/p/edc46c0f96c7</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[inheritance]]></category>
            <category><![CDATA[composition]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Steph Wong]]></dc:creator>
            <pubDate>Tue, 27 Feb 2018 19:22:11 GMT</pubDate>
            <atom:updated>2018-02-27T19:22:11.925Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bRZKRgn7lGK2LWFTXEq8Fg.jpeg" /></figure><h3>The Why</h3><p>As programmers, we should make our code as maintainable as possible. One way we can help achieve this is by utilizing the Object Oriented Programming patterns of Inheritance and Composition!</p><h3>What is Inheritance?</h3><p>Inheritance is defined as an IS-A relationship. This relationship is between two classes where one, referred to as the parent (or base or superclass), passes behavior down to another, referred to as the child (or subclass).</p><p>Let’s look at an example with three classes called Animal,Human and Raccoon, where Human and Raccoon inherit from Animal. To define the relationships we would say: Human is an Animal and Raccoon is an Animal. Animal is the superclass and Human and Raccoon are the subclasses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8htqCBgjNhIl8E49g6HZGw.png" /></figure><p>Inheritance is indicated with the &lt; symbol. In the example above, it would read as “Human and Raccoon inherit from Animal.” Even though we didn’t explicitly type methods for Human or Raccoon to eat, every human and raccoon instance will inherit the eat method from the Animal class. Once you start implementing more classes, utilizing inheritance can help save you from writing a lot of code!</p><p>Another thing to note is that when following inheritance, it is important to see if any methods can be generalized and grouped together. In the example above, walk and scuttle were grouped together in the Animal class as move. By doing this, we can reuse the basic functionality of move, and then within the Raccoon and Human classes, we can add whatever specializations are needed.</p><p>Inheritance is also transitive, meaning a class may inherit from another class which inherits from another class, and so on, up to the base class. To ensure that subclasses still control their own behaviors, subclasses are able to override methods and/or fields that were passed down to them, just like what we showed in our raccoon.move example above.</p><h3>What is Composition?</h3><p>Composition is defined as a HAS-A relationship. This relationship is between two or more classes where the use of instance variables are references to other objects. Or to put it in other words, when a class uses another object to provide some or all of its functionality. Let’s take a look at our example again, but this time refactored to utilize composition instead of inheritance. To define these relationships we would say: Human has Movement and Raccoon has Movement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xmEPYV1k2OJw7WKpNYoWvA.png" /></figure><p>In the example above, we define a Movement class with several methods. Human and Raccoon both have the ability to look into the Movement class by instantiating an instance of Movement within their respective initialize methods. From there, Human and Raccoon are able to use any of Movement’s methods.</p><h3>So, which one should you use?</h3><p>It depends! An important question to think about is whether or not that relationship will be constant throughout the lifetime of your application. For example, you say that a Programmer is a Human, therefore you should apply inheritance. But what if Programmer decides to change careers or become unemployed? The relationship between a Human and a Programmer is impermanent and would be better serviced through composition. Here are two rules that can help answer this question:</p><ul><li>It is better to use inheritance when your hierarchy represents an IS-A relationship. Inheritance is a great choice if your object already has a single responsibility and you really just want specializations.</li><li>It is better to use composition when your hierarchy represents a HAS-A relationship. Composition breaks up functionality into distinct responsibilities.</li></ul><p>Overall, inheritance and composition are both powerful patterns that we can utilize to improve our code maintainability. Some might say that composition is “better,” but it’s more so a question of which approach is more suited for your needs! Have fun trying them both out!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edc46c0f96c7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/entelo/understanding-inheritance-and-composition-in-ruby-edc46c0f96c7">Understanding Inheritance and Composition in Ruby</a> was originally published in <a href="https://medium.com/entelo">Entelo Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s Talk About JavaScript Promises]]></title>
            <link>https://blog.vanila.io/lets-talk-about-javascript-promises-be6cbd44a2da?source=rss-604827d75d18------2</link>
            <guid isPermaLink="false">https://medium.com/p/be6cbd44a2da</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[asynchronous]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[promises]]></category>
            <dc:creator><![CDATA[Steph Wong]]></dc:creator>
            <pubDate>Thu, 09 Nov 2017 00:28:22 GMT</pubDate>
            <atom:updated>2019-03-31T00:32:08.842Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TTUwLYB_gUAItQu7lqIxMQ.jpeg" /><figcaption>image by Stephanie Wong</figcaption></figure><figure><a href="https://community.vanila.io/"><img alt="" src="https://cdn-images-1.medium.com/max/880/1*oBt6QPSGBCr5krApJ4ruZw.png" /></a><figcaption>Community of digital makers — <a href="https://community.vanila.io/">Join now</a></figcaption></figure><p><strong>What is a Promise and why should we use them?</strong></p><p>If you’ve been programming in JavaScript for awhile, you’ve probably experienced your fair share of callbacks and entered “callback hell”. There’s a different approach to asynchronous program flow we can use called Promises.</p><blockquote>MDN states: The <strong>Promise</strong> object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value.</blockquote><p>Promises are much more intuitive because we can use our usual language features with terms like “return” and “throw” to handle value and error processing in synchronous flows. Promises represent a value that we can handle at some point in the future, and give us guarantees about that future value! Two guarantees are that Promises are immutable, and we will receive that processed end value.</p><p><strong>Is there anything a Promise can’t do?</strong></p><p>Well, you can’t cancel a Promise. Once created, it will begin executing. You also can’t track the status of a Promise, ie whether it’s pending, fulfilled or rejected.</p><p><strong>Here’s a real world example of a Promise:</strong></p><p><em>You are at the store and your friend promises to buy you an ice cream bar before you both leave.</em></p><p>You don’t know for sure if you will get that ice cream bar until you both are leaving the store. Your friend can either buy you the ice cream, or flake and leave you without any ice cream.</p><p>Promises have 3 states:</p><p>pending → your friend’s promise to buy you an ice cream bar<br>resolved → your friend buys you an ice cream bar<br>rejected → your friend does not buy you an ice cream bar</p><p><strong>Let’s Make our example into a Promise</strong></p><pre>new Promise( /* executor */ function(resolve, reject) { … } );</pre><p>The standard way to make a Promise is by using the new Promise constructor. This accepts a handler that is given two functions as parameters. The first handler is a function to call with the future value when it’s ready. The second handler is a function to call to reject the Promise if it can’t resolve the issue.</p><pre>var isFriendTruthful = false;</pre><pre>var willIGetIceCreamBar = new Promise( (resolve, reject) =&gt; {<br> if (isFriendTruthful) {<br>   var iceCream = {<br>   brand: ‘Godiva’,<br>   flavor: ‘strawberry’<br> };<br> resolve(iceCream); // The Promise was fulfilled successfully <br> } else {<br>   var reason = new Error(friend is not truthful);<br>   reject(reason); // There was an error, the Promise was rejected<br>   }<br> }<br>)</pre><p>A few things to note about Promises: it can only be fulfilled or rejected once. This is the Promise being “settled”. You can also immediately resolve a Promise if you use the Promise.resolve() method.</p><p><strong>Time for us to consume the Promise</strong></p><p>To consume the Promise means we want to process the Promise value once it has been fulfilled! To make this happen, we attach something called a handler, using the .then() method. This method takes a function that will be passed the resolved value of the promise. Take a look at the example below:</p><pre>// We have a function askFriend that will consume our promise willIGetIceCreamBar</pre><pre>var askFriend = function () {<br> willIGetIceCreamBar</pre><pre>// We use .then and .catch to handle our action</pre><pre>// What is the value of fulfilled? <br>// It is the value you pass in your resolve()<br> .then(function (fulfilled) {<br>   // yay, you got the ice cream!<br>   console.log(fulfilled);<br>   // output: { brand: Godiva, flavor: strawberry }<br> })</pre><pre>// What is the value of error? It is the value you pass in your reject()<br> .catch(function (error) {<br>   // oops, friend doesn’t buy it<br>   console.log(error.message);<br>   // output: friend is not truthful<br> });<br>};</pre><pre>askFriend();</pre><p>The .then() method takes two parameters. The first function called is when the Promise is fulfilled, while the second function is called when the Promise is rejected. If you use the standard Promise.catch(), you omit the first handler, setting it as null, and only provide the second handler to deal with the rejection. Using .catch() is more explicit and self-explanatory. You also only need to add a single .catch() at the end of a chain (which we will talk about next!) to handle any rejection or thrown errors within that chain.</p><pre>The following lead to the same outcome:</pre><pre>p.then((val) =&gt; console.log(“fulfilled:”, val)) <br> .catch((err) =&gt; console.log(“rejected:”, err));</pre><pre>p.then((val) =&gt; console.log(“fulfilled:”, val)) <br> .then(null, (err) =&gt; console.log(“rejected:”, err));</pre><p><strong>Chain the Promises!</strong></p><pre>// call our promise<br>var askFriend = function () {<br> willIGetIceCreamBar<br> .then(shareIceCream) // chain it here<br> .then(function (fulfilled) {<br>   console.log(fulfilled);<br>   // output: ‘Hey take a bite of this Godiva strawberry popsicle!’<br> })<br> .catch(function (error) {<br>   // oops, friend doesn&#39;t buy it<br>   console.log(error.message);<br>   // output: friend is not truthful<br> });<br>};</pre><p>This whole thing works because promise.then returns a promise, which we can call another .then on. When a handler returns a value, it becomes the result of that promise, so the next .then is called with it. It is worth noting that if the returned value is a promise, all further execution is suspended until that current promise has been settled.</p><p>To automatically reject a Promise, we can throw an exception. For example:</p><pre>var p1 = new Promise((resolve, reject) =&gt; { <br>  if (true) {<br>    throw new Error(“rejected!”); // same as rejection<br>  } else {<br>    resolve(1); <br>  }<br>});</pre><p>I hope you enjoyed my short introduction to JavaScript Promises! Promises will take a little practice before getting used to, but once you start getting into the flow of how Promises are composed, they’re a great resource to have in your toolkit. Thank you for reading!</p><p>Steph</p><figure><a href="https://community.vanila.io/"><img alt="" src="https://cdn-images-1.medium.com/max/880/1*oBt6QPSGBCr5krApJ4ruZw.png" /></a><figcaption>Community of digital makers — <a href="https://community.vanila.io/">Join now</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be6cbd44a2da" width="1" height="1" alt=""><hr><p><a href="https://blog.vanila.io/lets-talk-about-javascript-promises-be6cbd44a2da">Let’s Talk About JavaScript Promises</a> was originally published in <a href="https://blog.vanila.io/">Vanila Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Deal with JavaScript Closures–Why, How, & When to Use Them]]></title>
            <link>https://stephaniewo.medium.com/how-to-deal-with-javascript-closures-why-how-when-to-use-them-25b4dd0beff8?source=rss-604827d75d18------2</link>
            <guid isPermaLink="false">https://medium.com/p/25b4dd0beff8</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Steph Wong]]></dc:creator>
            <pubDate>Fri, 03 Nov 2017 16:22:14 GMT</pubDate>
            <atom:updated>2021-02-01T19:49:53.374Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XiS_1UijfHywHGIbHGdD7g.png" /><figcaption>graphic by me!</figcaption></figure><p>JavaScript closures were really hard for me to understand because I was under the misconception that I was being told to understand something new–when actually, closures were just an explanation of how something works, when you already expected them to work that way. Another point of confusion for me was that whenever I read about them, there was never any context. I was told the what, but I never understood the why. Today, I will explain what closures are, go through some examples, then end with points to keep in mind when applying closures in your code.</p><p><em>What is a closure?</em></p><p>A closure is a function object that retains ongoing access to the variables of the context it was created in (even after the outer function calls it was created within have returned. To state this in more general terms, whenever you see a function keyword located within another function, the inner function has ongoing access to the variables in the outer function. Another important thing to note is that a function doesn’t have to be returned in order to qualify as a closure. The ability to retain access to the variables outside of the immediate lexical scope qualifies as a closure.</p><p>The best way to understand closures, is to work through examples. Let’s dive in!</p><pre>Example 1: </pre><pre>Var multiplyByA = function(a) {<br>  return function(b) {<br>    return a * b;<br>  }<br>}</pre><p>Let’s start off with a simpler example. When a JavaScript function is invoked, a new execution context is created. The function arguments, along with the parent object, all are received into the new execution context. In the example above, the inner function retains access to the variables ‘a’ and ‘b’.</p><pre>Example 2:</pre><pre>var makeIncrementer = function(x) {<br>  var adder = function() {<br>    return x += 1;<br>  }<br>  return adder;<br>}</pre><pre>var incrementer = makeIncrementer(4);<br>console.log(incrementer()) // -&gt; 5<br>console.log(incrementer()) // -&gt; 6<br>console.log(incrementer()) // -&gt; 7</pre><p>In this example, the adder function still has access to the ‘x’ argument from the parent scope.</p><p>This is all great, but what’s the point of creating closures? After realizing what opportunities closures offered, I understood why they are necessary. Here is an analogy that really helped me:</p><p>Jojo is sitting in a car. The car is inside of a plane. That plane is at the airport. Jojo is still able to access the things in the plane, even if the plane takes off from the airport!</p><p>With code, let’s say you have a function that returns functions, a function factory. With closures, you give others access to the output function, without explicitly giving away how those functions are made.</p><p>Key points to remember about closures:</p><ul><li>A closure is not only created when you return an inner function</li><li>A closure does not reference a copy of the old values of variables in its scope. The variables themselves are part of the closure, and so the value seen when accessing one of those variables is the latest value at the time it is accessed.</li><li>The variables in a closure include any named functions declared within the function.</li></ul><p>I hope this cleared up any confusion there may have been about closures! Feel free to ask any questions or comments. Thank you for reading!</p><p>Stephanie</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25b4dd0beff8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Breadth First Tree Traversal with JavaScript]]></title>
            <link>https://stephaniewo.medium.com/understanding-breadth-first-tree-traversal-with-javascript-9b8fe670176d?source=rss-604827d75d18------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b8fe670176d</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[trees]]></category>
            <dc:creator><![CDATA[Steph Wong]]></dc:creator>
            <pubDate>Mon, 02 Oct 2017 04:45:51 GMT</pubDate>
            <atom:updated>2017-11-03T16:27:33.200Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GVLPan00OknU7TEQ0Q9ZJw.png" /><figcaption>Graphic by me!</figcaption></figure><p>Trees? Data? Together?? When I was first introduced to tree data structures, I had no idea how to visualize them or know what to do with them! Data trees can seem very daunting with their layers within layers, but after familiarizing myself with their structure and organization, I realized that trees are our friends. Let’s get started so you can too!</p><h4><em>What is a tree?</em></h4><p>A tree is a data structure comprised of several layers of related nodes. Each node contains a value and a list of it’s children. There are a few different kinds of trees, such as a binary tree or a binary search tree, but today we will be working with the basic tree structure.</p><p><em>Important keywords</em></p><ul><li><strong>Root: </strong>The top node of the tree</li><li><strong>Child:</strong> A node directly connected to another node when moving away from the Root</li><li><strong>Parent:</strong> The node connected above the child node</li><li><strong>Ancestor:</strong> A node reachable by repeated proceeding from child to parent</li></ul><p><em>Traversing breadth first through the tree</em></p><p>Going through each node of the tree is called: traversing the tree. There are different approaches to what order you want to step through the nodes. We are going to do a breadth first approach which means we will be walking across each level. There is also a depth first approach, where we step down each child, going back and forth between different levels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3NKvODZparRFVKEwtVmrkw.gif" /><figcaption>gif of breadth first tree traversal created by Stephanie Wong</figcaption></figure><p><em>Tree Use Cases</em></p><p>One reason to use a tree data structure might be so you can store data in a way that preserves a hierarchy. For example, the way you organize your files in a file structure. Another reason for using the tree data structure is that we can search through it more efficiently than other data structures. Trees can be traversed with a O(log(n)) time complexity. Since we can search through it more quickly, we can also made edits/updates faster as well.</p><p><em>Different Types of Trees</em></p><p>There are different types of tree data structures, each with special properties to optimize sorting and storing your data sets. The most basic tree structure is the <strong>binary tree </strong>where each node can have up to two children at most. There is the <strong>binary search tree</strong>, where the left child node must contain a value that is less than the parent node, and the right node must contain a value that is higher than the parent node. Another type of tree is the <strong>splay tree</strong>. This is a self-adjusting binary search tree, where the recently accessed elements are easily accessible again. When searching through the tree, you are also splaying–rearranging the tree so that the element is placed at the root of the tree. If you’re curious about other tree types, take a look here: <a href="https://en.wikibooks.org/wiki/Data_Structures/Trees">https://en.wikibooks.org/wiki/Data_Structures/Trees</a>.</p><p><em>Our Sample Problem</em></p><p>Implement a BreadthFirstTraversal method. BreadthFirstTraversal accepts a filter function, calls that function on each of the nodes in breadth first order, then returns a flat array of the node values from the tree that return true. We should also be able to declare a depth value and return all the nodes located at that depth.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ebb8060fe5231d2050bfe312d17240a/href">https://medium.com/media/3ebb8060fe5231d2050bfe312d17240a/href</a></iframe><p>Let’s think of our approach here. It’s always better to get a strong mental model before jumping into code!</p><p><em>What is our given input?</em></p><p>We are given a tree at the root node, and a filter function.</p><p><em>What is our desired output?</em></p><p>We expect a flat array of all the values that resulted true from our filter function. Since we want to perform our filter function in the correct order, let’s use a queue to store our nodes. The queue will allow us to have a first in, first out ordering of the nodes.</p><p>Below is the code for one possible working solution. Let’s walk through each line and explain what is happening!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3c7cb7731aa3a2be2587af3655996b3/href">https://medium.com/media/b3c7cb7731aa3a2be2587af3655996b3/href</a></iframe><p>The best way to understand this code is to step through it line by line. Try using the sample example data I provided above and walk through the code. Overall, the key to doing a breadth first tree traversal is understanding that you need to process the nodes in the right order. As long as they are pushed into the queue in the correct order, you are hitting that goal!</p><p>Thank you so much for reading! Once you start seeing the pattern of trees, they won’t seem as scary anymore. I hope this example helped clarify any questions you might have had about breadth first tree traversal. Please like this post if you found it helpful! Feel free to leave any feedback below! Until next time!</p><p>Stephanie</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b8fe670176d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>