<?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 Anna Brakowska on Medium]]></title>
        <description><![CDATA[Stories by Anna Brakowska on Medium]]></description>
        <link>https://medium.com/@anna.brakowska91?source=rss-2180b19ee8cc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4fQCiSbQ3HXngxeK1ZlSqA.jpeg</url>
            <title>Stories by Anna Brakowska on Medium</title>
            <link>https://medium.com/@anna.brakowska91?source=rss-2180b19ee8cc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 01:23:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anna.brakowska91/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[Like phoenix from ashes…]]></title>
            <link>https://medium.com/@anna.brakowska91/like-phoenix-from-ashes-b59778898423?source=rss-2180b19ee8cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/b59778898423</guid>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Anna Brakowska]]></dc:creator>
            <pubDate>Thu, 20 Dec 2018 18:01:02 GMT</pubDate>
            <atom:updated>2018-12-20T19:35:53.015Z</atom:updated>
            <content:encoded><![CDATA[<h3>Like a phoenix rising from the ashes…</h3><h4>The unknown story of React’s Context API</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*RxETebw-tJDGShPd2ACFRQ.gif" /></figure><p>A looong loooong time ago…… in the early days of React, the only way to manage application state was through prop drilling… but the deeper the component nesting was, the deeper the props had to be drilled. The Context API was hated… even by it’s own creators —the noble Facebook Engineers, who strongly advised against using it in their official documentation.</p><p>In 2015, a clever brother engineer named Dan Abramov, came up with a great solution. He developed Redux to solve all of the problem we had with passing props down to the components. He created this magic framework that finally(!) allowed you to get data from the store easily, anywhere in the tree.</p><p>Unfortunately setting up Redux was not always that easy to start with because of it’s enormous amount of boilerplate. Thus, the Greatest Engineers at Facebook sat down and conversed again… Something had to be changed. They took the old hated Context API and burnt it down to its ashes… and from the ashes a phoenix was born — the New Context API, reborn, beautiful, sparkling, context.</p><h4>The power of The New Context API</h4><p>Back to reality. “Why and how the heck do I use it?” you may ask. Well, the New Context API can be used as a simple state manager. It will shine bright in your projects, where you need a simple way of passing data and functionality deep down to the lowest components in the tree, but Redux would be considered over-engineering for the needs of the particular application.</p><h4>The New Context API Structure</h4><p>The basic idea behind the New Context API is that state is being held in the <strong>provider</strong> component. You send the values you want to pass down by returning a context <strong>provider</strong> component with the passed <strong>values</strong>.<strong> </strong>You receive the values in a component further down the tree by wrapping the chosen element in a context <strong>consumer</strong> wrapper. The Consumer takes an anonymous function that takes an object — the value object that you passed down. You can name it anything you want, so let’s call it ‘context’. That anonymous function returns an element with the values it got from context. Don’t get scared, this isn’t that complicated. We will look at the code in one second, but let’s have a look at the basic structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*XnXi6CXcEtRGvdxl2H6h5A.png" /><figcaption>The structure of the New Context API with one Provider</figcaption></figure><p>Notice that the Provider holds the state (your value bypasses all other components), and goes straight to the deeply nested element in the tree. It doesn’t get passed through; it just bypasses everything else, and goes straight there.</p><h4>How to set up the New Context API with one Provider</h4><ol><li><strong>Create context instance</strong>.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67790e9a6349cca78b9fd9340c9dbad9/href">https://medium.com/media/67790e9a6349cca78b9fd9340c9dbad9/href</a></iframe><p>2. <strong>Create a provider component</strong> that returns a provider wrapper with the value you want to pass down (you can name that <strong>provider</strong> component Bananas if you want, but let’s be consistent with the component name). From now on this is going to be our single source of truth. It holds state as you see in line 4, and returns the Context wrapper with the value we gave it — lines 11 and 12. Notice that the value holds not only data, but also methods that you want to pass down. Line 21 — this line simply indicates that we will be nesting some elements there.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7901b38f85febbca4741297339d026f5/href">https://medium.com/media/7901b38f85febbca4741297339d026f5/href</a></iframe><p>3. <strong>Create App component</strong> — this is our main component that will be rendered by ReactDOM. Notice that we don’t pass any props to the FruitComponent, and App component doesn’t even have state. Easy, right?!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1174ee60c050bb0a6c6a000fbab237f/href">https://medium.com/media/d1174ee60c050bb0a6c6a000fbab237f/href</a></iframe><p>4. <strong>Create a component that you want to pass props to.</strong> In my example we will have a component holding fruits, I called it FruitComponent.</p><p>Now, the magic of passing props directly to our chosen component is a little tricky. You have to wrap the element that gets the props in your previously created context with the Consumer wrapper. *The element I want to pass props to starts at line 8 — *the React.Fragment I want to pass my favorite fruit, the amount I ate, and an increase method. I have to unpack my context that was sent from the Provider as a value. Line 7 — I declared an anonymous function that will deliver the context, and then… just take what you need from the context.</p><p>*Notice you can only wrap one element. If you have a group of elements you want to pass props to, then you have to wrap them in a single div, React.Fragment or &lt;&gt;&lt;/&gt;.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c6de3b77a4b886bb16e348b35cac66c/href">https://medium.com/media/3c6de3b77a4b886bb16e348b35cac66c/href</a></iframe><h4>Set up the New Context API with two Providers</h4><p>“Can I have two providers?” you may ask… Yes you can! Let’s see how we would refactor for that.</p><ol><li><strong>Create a second instance of context</strong></li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c37ba2bb477d285607a999203015b46/href">https://medium.com/media/1c37ba2bb477d285607a999203015b46/href</a></iframe><p>2. <strong>Refactor the Provider </strong>component so it can take another context by nesting it in a previous context. Eeeeeasy! Second context in the first context — line 12 we are starting first context, passing some value. Right after the closing tag, we are nesting a second context with another value. Notice that this.props.children goes inside the last nested context, so we can have access to all passed values.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02a1b24e8a68c479287b7b76ad34ccef/href">https://medium.com/media/02a1b24e8a68c479287b7b76ad34ccef/href</a></iframe><p>3.<strong> Nothing changes in the App component,</strong> as it doesn’t get any props. as it doesn’t get any props. We can go straight to step 4.</p><p>4. <strong>Refactor the FruitComponent</strong> so it can unpack passed values. We are using an anonymous function to pass values from the first context, which leads us to a second context, where we also have to unpack the passed value by using an anonymous function. Finally, we can start using the values! Line 11 — here go the apples I passed in the second context.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89159520cbcbbcd04600e8a020ac53b6/href">https://medium.com/media/89159520cbcbbcd04600e8a020ac53b6/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*668fFMYDFK9ROfkByQ9OoA.png" /><figcaption>The nested structure of Context API with two providers</figcaption></figure><h4>Default Values</h4><p>But, what if there was no Provider? How would context know what to pass? Weeellll, our beloved new context is smart enough to know, that when it doesn’t find a Provider, then it goes to its own parents to check if any parameter was passed. If it was, then it would pass that data. So now you can guess, when line 13 renders, what will you see? That’s right, cucumber.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56b295f131c0e1030c3ae37ec89fba52/href">https://medium.com/media/56b295f131c0e1030c3ae37ec89fba52/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*u_QmyKA4mhycp7FY8mXACQ.jpeg" /><figcaption>Trust Chuck Norris, he knows Context API.</figcaption></figure><p>This is more or less what you should know about the New Context API. But to answer your burning question — “will it replace Redux?????”, unfortunately… I don’t think it will. Redux, no matter how complicated and boilerplated is, has it’s purpose. I encourage you to use the New Context API wherever your application can… but don’t be surprised that it may not be enough if you are building a bigger project. (That’s when you may need Redux.)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b59778898423" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Legacy code to GraphQL in less than minute with TentaQL]]></title>
            <link>https://medium.com/@anna.brakowska91/legacy-code-to-graphql-in-less-than-minute-with-tentaql-a1a280343dd9?source=rss-2180b19ee8cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1a280343dd9</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Anna Brakowska]]></dc:creator>
            <pubDate>Wed, 05 Dec 2018 20:49:31 GMT</pubDate>
            <atom:updated>2018-12-06T18:44:06.533Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Legacy code to GraphQL in less than a minute with TentaQL</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/0*oV4h8CUEOUm_uuno" /></figure><blockquote>TentaQL is an automated SQL and NoSQL introspection and GraphQL conversion tool, providing users a highly customizable GraphQL package to get their legacy databases up and running with GraphQL in minutes.</blockquote><h3>What is GraphQL?</h3><p>I’m sure you probably heard of GraphQL by now, but for those who have not, let me review the concept one more time. GraphQL is a query language, introduced by Facebook, as a more efficient and flexible alternative to REST architecture. However, unlike REST, GraphQL uses a single endpoint to fetch, mutate (or change) data. And here we are getting to the meat and potatoes of GraphQL. Schemas! All the operations are achievable thanks to the concept of strongly typed schemas, whose main purpose is to ultimately provide flexible access to underlying data through through composition, selection, and resolution.</p><h3>What seems to be the problem?</h3><p>Despite the flexibility and richness of the query language, the process of writing schemas, mutations and resolvers is extremely repetitive, time consuming and adds a great deal of complexity to the process of starting a new application, or switching REST architecture to GraphQL.</p><h3>TentaQL as a solution!</h3><p>Requiring only your remote database URL, TentaQL is able to access the database, recreate the schema and auto generate a full GraphQL server, schema and resolvers, available for download or edit. In just a few simple steps you can start implementing your new application.</p><h3>How to use</h3><p>Visit TentaQL and enter your database URI. To translate your database to GraphQL click on <em>“Convert Your Database Now”.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*B3y0dVtwc-tlKEWi" /></figure><p>2. After your database content was translated to GraphQL, you will see the output in the fully functional code editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*POz1M5BDd3BP00Vj" /></figure><p>3. The editor allows you to view schemas, or resolvers, as well as a copy of a particular tab, or download original or edited by you translation of the legacy code. After editing code, you can review it or optionally revert back to original version by clicking at <em>“Reset Tab”.</em></p><p>Visit us at <a href="https://github.com/TentaQL/tentaQL">github repo</a> or our <a href="https://www.tentaql.com/">site</a>, feel free to play around, and don’t forget to let us know what you think!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1a280343dd9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linked lists… why so many pointers?]]></title>
            <link>https://medium.com/@anna.brakowska91/linked-lists-why-so-many-pointers-3a285c427af5?source=rss-2180b19ee8cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a285c427af5</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Anna Brakowska]]></dc:creator>
            <pubDate>Mon, 03 Dec 2018 14:01:02 GMT</pubDate>
            <atom:updated>2018-12-04T01:38:49.837Z</atom:updated>
            <content:encoded><![CDATA[<p>My first encounter with linked lists was some time ago. All I could remember was…pointers. Many, many, maaaaaaaany pointers. I didn’t know where they were pointing, some heads, and tails and… pointers. It took me some time and some good explanation to finally organize the pointers and find out why there were so many of them — here I would like to thank a great data-structures mentor of mine — <a href="https://medium.com/u/f326957a2149">David DeStefano</a> (if you are reading this, this one is for you :) Let’s dive in some basics: benefits and drawbacks of using linked lists, how to add and remove nodes.</p><h4><strong>What exactly is a linked-list?</strong></h4><p>Let’s have a look at Wikipedia’s definition.</p><blockquote>In <a href="https://en.wikipedia.org/wiki/Computer_science">computer science</a>, a <strong>Linked list</strong> is a linear collection of data elements, whose order is not given by their physical placement in memory. Instead, each element <a href="https://en.wikipedia.org/wiki/Pointer_(computer_programming)">points</a> to the next. It is a <a href="https://en.wikipedia.org/wiki/Data_structure">data structure</a> consisting of a collection of <a href="https://en.wikipedia.org/wiki/Node_(computer_science)">nodes</a> which together represent a <a href="https://en.wikipedia.org/wiki/Sequence">sequence</a>. In its most basic form, each node contains: <a href="https://en.wikipedia.org/wiki/Data_(computing)">data</a>, and a <a href="https://en.wikipedia.org/wiki/Reference_(computer_science)">reference</a> (in other words, a pointer) to the next node in the sequence.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*8Y7cyyjVWnoni62_wiZrjg.png" /></figure><h4>Why would you use linked-list?</h4><p>Here are some real world cases where you could use linked lists:</p><ul><li>you need to make a lot of insertions or deletions (using an array requires shifting elements every time you want to insert or delete something, and this operation is expensive)</li><li>you don’t need random access to your data (the only entry you have is head and tail)</li><li>dynamic structure allows linked-lists to grow and shrink at runtime</li></ul><h4><strong>Drawbacks:</strong></h4><ul><li>no random access to nodes other than head or tail (using doubly linked-list allows access to a previous node)</li><li>accessing a given node or locating the place where a new node should be inserted — may require iterating through most or all of the list elements</li><li>linked-lists use more memory than arrays because of the pointers</li><li>traversal and reverse traversal are complicated (in case of doubly linked list reverse traversal is a little easier, because you have previous pointers, but storing them requires more memory)</li></ul><h3>Coding time</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/203/1*snpiGr4uRbjKGuBbJgwzKg.png" /></figure><h4>How to add new nodes?</h4><p>Well, first we need to create a node. Let’s have a look at the code below to see how we can create that node. We are going to use ES6 classes for all operations.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2b6151763e1bbed6dd2e9088ff23c35/href">https://medium.com/media/f2b6151763e1bbed6dd2e9088ff23c35/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*Oyav3mAZS_VmiIUSzP1Q-A.png" /><figcaption>Initially the instance of Node class carries some value, but the pointer that specifies which node should go next points to null.</figcaption></figure><p>So, what would happen if we just created a whole bunch of nodes? The universe of random nodes floating around would happen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*zYP_1xAxM91f1Nou9jWthQ.png" /></figure><p>You probably noticed, that in order to make a list out of this chaos, we need some structure, that would have some magic powers to connect these nodes using pointers. Let’s define that new class and give it a method responsible for adding new nodes to the list.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e9796575dd86723634f4355912ad3b2/href">https://medium.com/media/5e9796575dd86723634f4355912ad3b2/href</a></iframe><p>Every time we want to insert a new node to our list, we have to check a few things. The first question we have to answer is: does the list contain any elements?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*QvvRWmW1-d4DZeC0PlFb7w.png" /><figcaption>head and tail are pointing to null, our list is empty</figcaption></figure><p>If the situation looks like this, our linked list will just insert a node by pointing head and tail to that node. Node’s next pointer will still be pointing to null.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/363/1*ztpuLBGS3p_sLZOs-2ueLg.png" /></figure><p>But now, the list is not empty. What do we do?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*yiaJTRGx_DE_r6XChQoR3g.png" /></figure><p>In that case we need to:</p><ol><li>create a new node</li><li>point the last node that we have in the list to our new node, and finally point tail to that new node</li></ol><p>***if we repointed tail first, then tail would be removed from the list. Make sure you repoint next first and tail after***</p><h4>How to remove nodes?</h4><p>Now, how do we remove nodes from the list? This is a longer process, but don’t get overwhelmed. There are just a couple of cases we need to cover. Let’s see:</p><ol><li>node to be removed happens to be located in the head (just remove it)</li><li>node is not in the list (iterate over all nodes and break from the loop if we did not find our node)</li><li>node to be removed is tail (requires a loop)</li><li>node is somewhere inside (requires a loop)</li></ol><p>So how would that look? Let’s see (I will skip case no.2, you just have to break from the loop):</p><p><strong>Case no. 1— remove head</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*uZzCnkHC6gUReonYMerx1w.png" /><figcaption>Case no.1 Remove head</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*parpo38nX-xyFZP-p06UwQ.png" /><figcaption>You only have to change the position of your lists’s head. The rest will be taken care of by garbage collection.</figcaption></figure><p><strong>Case no.3 — remove tail</strong></p><p>Removing tail is a little more complicated. In this case we need to traverse through the entire list to the tail and stop one node before the tail (this is a singly linked list, and it does not have access to information about previous nodes, you can only move forwards). We stop on that previous to last node, and from here it gets easier. We need to reassign tail to that node, and point tail’s next pointer to null. Case no.2 job is done. (***important notice: take care of reassigning tail first, by doing that you won’t lose the connection between tail and your list, otherwise tail will be removed together with the node)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*JMICtRwZEAHSBkI3lDHgEw.png" /><figcaption>Steps to remember here: reassign tail to previous node, point this new tail to null.</figcaption></figure><p>Case no.4 — remove node from the middle of the list.</p><p>This case is fairly simple. We obviously need to traverse through the list to find the node we need to remove. The same as in the previous case, we have to make sure the loop stops one node before our node. Now, after we found the previous to our node, we can reassign it’s next pointer to point to our node’s next and we can break from the loop. The job is done here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*EooVoDnpYvIjjD8ijQ8WdA.png" /></figure><p>This is how it looks in the code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8461b55a54eb390439f73c743bfe82ef/href">https://medium.com/media/8461b55a54eb390439f73c743bfe82ef/href</a></iframe><p>And this is in short how we create a singly linked list. I hope my post helped you. As always, don’t get discouraged if you don’t fully understand data structures, they tend to be tricky, but I’m sure, over some time you will get it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a285c427af5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Insertion sort made easy]]></title>
            <link>https://medium.com/@anna.brakowska91/insertion-sort-made-easy-354559d6712a?source=rss-2180b19ee8cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/354559d6712a</guid>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Anna Brakowska]]></dc:creator>
            <pubDate>Wed, 28 Nov 2018 18:47:40 GMT</pubDate>
            <atom:updated>2018-12-04T01:15:35.243Z</atom:updated>
            <content:encoded><![CDATA[<p>The subject of algorithms always seemed impenetrable for me. I would attempt learning it enthusiastically, only to give up with a headache, after some time of blindly staring at the convoluted definitions, and solutions that did not mean anything to me. It was that way until I realized how simple and elegant algorithms can be when you have them explained and visualized step by step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*_5_DM2MA2uLOef-qpbTdwQ.png" /><figcaption>That was me tackling the algorithms for the first time, and the second aaaand the third… :)</figcaption></figure><p>If you are an algorithm genius, this post may be too easy for you… but if you are like me, not a fan of algorithms but! determined to get better let’s do it. Let’s dive into it together.</p><p>Today we’re gonna fight <strong>insertion sort</strong>. First things first. Let’s have a look at the definition.</p><blockquote>Insertion sort algorithm iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there. It repeats until no input elements remain. <strong>From </strong><a href="https://en.wikipedia.org/wiki/Insertion_sort"><strong>Wikipedia</strong></a></blockquote><p>Now how does it really translate into code? In simple pseudocode the algorithm will look like this:</p><p>You need to understand that there are going to be two portions of our array. The left portion that is sorted and the right portion that is unsorted. We are going to iterate over an unsorted portion of the array (initially unsorted portion starts from the second item of the array). Our goal is to get the current number and be swapping it to the left with it’s neighbors until it finds the right place and we can insert it (swapping with all unsorted numbers until we reach sorted). By doing this, we will slowly build up the sorted portion of an array until everything is sorted and we can return the sorted array. The condition that determines if the number has to be swapped is: is the left number larger than the current number?</p><p>Steps:</p><ol><li>Create an outer loop that starts from the second number and iterates to the last number of the array (we will start from the second item of the array because the first number is already sorted, right?).</li><li>Assign the value of the current number to a temporary variable that will be reassigned every iteration.</li><li>Initiate an index for the inner loop, that index will be the same as index for outer loop. However outer loop will be moving forwards to pick a next number that has to be sorted, and inner will be moving backwards in order to find that number’s place.</li><li>Condition for your inner loops is: keep moving until your index is greater or equal to 0 <strong>and</strong> as long as the value of the current number is less than it’s left neighbor’s value. During every iteration swap current number with the number on the left.</li><li>When the inner loop stops, it means it found the place to insert the current number.</li><li>After outer loop stopped we can return the sorted array.</li></ol><p>Now how would that look in the Javascript? Let’s see below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96f71804730d9783a41754412627207b/href">https://medium.com/media/96f71804730d9783a41754412627207b/href</a></iframe><p>There is nothing better than a visual representation. So let’s have a look at how that algorithm is acting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*h_ujrRbcaWG63PyhEg7nWA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*D1zP_TtKspyu2VVYskgH2g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/263/1*QkuTnYDFq5o1I26M_ZqbCw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*ZdOlUjKNMiJj5enxFOpNqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*ro4AWGLpkwdOunn4oXVVdg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*pYR3TIwZszKcgPBNR-RTLg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*wLUK3yeNeu4Ra5W_8A1RaA.png" /></figure><p>I hope my explanation helped you understand insertion sort a little better. It may take some time until it really click, but don’t get discouraged, take some time and I’m sure you will understand it. Drop me a comment and let me know what you think so I can get better at writing :)</p><p>There are a couple of extremely helpful additional resources:</p><ol><li>For visual learners I highly recommend this website: <a href="https://visualgo.net/en/sorting">https://visualgo.net/en/sorting</a></li><li><em>“Grokking algorithms”</em> by Aditya Y. Bhargava</li><li><em>“Learning Javascript Data Structures and Algorithms”</em> by Loiane Groner</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=354559d6712a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>