<?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 Ethan Hess on Medium]]></title>
        <description><![CDATA[Stories by Ethan Hess on Medium]]></description>
        <link>https://medium.com/@erhess0011?source=rss-8643d24c9e53------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*OsnRWzea_IH6ro8s</url>
            <title>Stories by Ethan Hess on Medium</title>
            <link>https://medium.com/@erhess0011?source=rss-8643d24c9e53------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 07:01:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@erhess0011/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[Javascript Currying]]></title>
            <link>https://medium.com/@erhess0011/javascript-currying-8e907e9de713?source=rss-8643d24c9e53------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e907e9de713</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ethan Hess]]></dc:creator>
            <pubDate>Mon, 12 Nov 2018 14:54:15 GMT</pubDate>
            <atom:updated>2018-11-12T14:54:15.041Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wpD4yQszc2Q9njT9YWgEYg.png" /></figure><p>A curried function is a function that takes multiple parameters one at a time: So, it takes a parameter, and returns a function that takes the next parameter, and so on until all parameters have been supplied, at which point, the application is completed and the final value is returned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gVRINxZZwYs1s1DJ" /></figure><p>This is an example of a very basic curried function. Taco is the name of the curried function; it is designed for the first argument to be pre-filled before the function itself is fully executed. With this pattern, ‘steak’ can be bound to taco’s ‘a’ parameter, and the other ingredients can be bound to the ‘b’ parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/0*Sh6PipO3zAd4K4UX" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/0*-g-kJiwrzTAj95CY" /></figure><p>Furthermore, currying can be integrated with callbacks to create higher-order ‘factory’ functions. This pattern is extremely useful in event handling, and can also replace the callback pattern that is utilized in node.js The top image is an example of combining currying with node.js to process a file. At first it may not seem like much happened here, but this pattern is actually quite powerful. Integrating node with curried functions allows for the read data to be passed around to other bits of code as the file is getting processed. So we can postpone invoking the read function’s callback until the result is needed. The bottom image demonstrates that currying node.js functions can also allow for sequential processing of multiple files, much like the async library for node.js.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/0*qoSOM4uJOKQu-3M-" /></figure><p>The one downside to currying is that it’s not a pattern that is native to javascript, so it is often handy to write a (currier) utility function that can transform any given function into a curried version of itself. So what this is doing is it defines the args variable and sets it to the second argument passed in, since the first should always be a function. Then it returns an anonymous function, and that will then return the function passed in and applying to it the other arguments being passed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/0*-ZNX3ikWOthJ7GQs" /></figure><p>So with that said, we have this sequence function which takes a start and end position and should return an array of sequential numbers between those two positions. Now we can declare a variable (seq5) and set it to an invocation of our utility function and pass sequence as our first argument and 1 as the second argument. After that, we can use seq5 to input our end position, in this case 5. And as you can see if we were to console log this we would get an array of numbers from 1–5 in order.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7Lxyz6jIOm1efAfc" /></figure><p>So in conclusion, adding currying to your coding practice will encourage the use of partially applied functions throughout your code, avoiding a lot of potential repetition, and may help get you into better habits about naming and dealing with function arguments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e907e9de713" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MongoDb]]></title>
            <link>https://medium.com/@erhess0011/mongodb-bd0986d85e1e?source=rss-8643d24c9e53------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd0986d85e1e</guid>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Ethan Hess]]></dc:creator>
            <pubDate>Mon, 22 Oct 2018 14:05:27 GMT</pubDate>
            <atom:updated>2018-10-22T14:05:27.220Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qwt-JhtW8FXEpXX2rpo4Zw.png" /></figure><p>MongoDB is an open-source, non-relational, or NoSQL, database that stores data as documents in a binary representation called BSON, which stands for Binary JSON. Essentially what BSON is, is a binary form for representing simple data structures, associative arrays, and various data types of specific interest to MongoDB. Furthermore, MongoDB’s document data model maps naturally to objects in application code, making it simple for developers to learn and use. Documents also give you the ability to represent hierarchical relationships to store arrays and other more complex structures fairly easily.</p><p>So to get started, we must know that MongoDB applications consist of the three basic components: Establishing a connection to a MongoDB instance. Having logic to access and manipulate database data. Closing the connection to the MongoDB instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r1XLGkmDdFcB1GgfiWZNlg.png" /></figure><p>Before any requests can be made to MongoDB, a connection must first be created. Establishing a connection is similar to placing a telephone call in that you need the “phone number” of the MongoDB instance and the database it will interact with. This “phone number” is made up of the host name of the MongoDB instance and the specific database name</p><p>In addition to the “phone number” there are other optional parameters such as the user id and password, for this demonstration that wont be necessary, but typically for security reasons you would want to have those optional parameters as well incase the database contains sensitive information</p><p>So, since database access is typically distributed across more than one source file in an application, a best practice is to isolate the host and database names into a config.js file that is shared across all application components. The advantage of this is that altering either or both of these host or database names only requires an update to the config.js file, rather than to each application source file that requires a connection. The contents of the config.js file are on the right side of the screen. As you can see we create a config object with a property of db set to another object. We then create properties on the config.db object set to the host and database names, in this case we have them set to a local host and a name of ‘account’. We then export the config object so that it can be used in other components that require this file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ejEJ0O65y9LFoPcrCCgIcQ.png" /></figure><p>So now we move on to a file named index.js to establish a MongoDB connection using the properties in the config.js file. To do so, a require must be issued to allow the properties in it to be referenced from within the source file creating the connection. These properties are then used to create the URI connection string and a MongoClient reference that subsequent database requests will be issued through. The first such request is mongoClient.connect(mongoUri) which creates the connection and returns a reference to the client instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mmqFk1TubmMoa4Oo23wt-g.png" /></figure><p>Once a connection has been established, the application is ready to access and manipulate documents in the database. The first step in this process is to define the document collection within the database. This is conceptually similar to a table in a relational database, but unlike those tables whose rows all have the same format, a collection can contain different types of documents, each having a different format. In this example the collection is created by the function call: collection = accountsDb.collection(‘accounts’); which defines a reference to a collection called ‘accounts’. Once the collection is created it can be used to invoke MongoDB function calls to access documents in the database. For example, collection.count()returns the number of documents in the collection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IGlld0wip4ddW5QVBz2mTg.png" /></figure><p>After the application has completed its goal and no more data is to be retrieved from the database, it’s a good practice to gracefully terminate the connection to the MongoDB instance. This is accomplished by simply closing the connection. In the example above this is done by calling the accountsDb.close() function to stop the connection and free up any resources devoted to it. Also just to add, you may have noticed that in the first .then(db) function, the value of db was saved to a variable called accountDb. This was done in anticipation of it being needed later in the application logic to close the connection. And it was necessary since the scope of db is limited to that first .then(db) function. One additional consideration is there are cases where you may not want to close the connection. Since opening and closing connections are relatively expensive, high volume applications might want to use connection pooling to reuse connections rather than continually opening and closing new ones.</p><p>In conclusion, MongoDB is a popular NoSQL database solution that suits modern development requirements. It has a great query DSL, wonderful developer documentation and libraries, and built in support for scaling and replication. When it comes time to choose your production database however-as with any technology — you should do your research, and find out if MongoDB fits your requirements.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd0986d85e1e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Frameworks vs Libraries]]></title>
            <link>https://medium.com/@erhess0011/frameworks-vs-libraries-3b40bf46e4ab?source=rss-8643d24c9e53------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b40bf46e4ab</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ethan Hess]]></dc:creator>
            <pubDate>Mon, 15 Oct 2018 13:10:20 GMT</pubDate>
            <atom:updated>2018-10-15T13:10:20.715Z</atom:updated>
            <content:encoded><![CDATA[<p>What is a framework?</p><p>For starters, a framework is described as “an abstraction, in which a software that provides generic functionality can be selectively changed by additional user-written code, thus providing application-specific software”. Now, what do I mean by abstraction? Well, in programming it describes something that is half finished, when it’s up to a user to fill the gaps to complete it. Another thing to note about “abstraction” is that it already contains information about what those gaps are and how they should be filled.</p><p>Unlike in libraries or in standard user applications, the overall program’s flow of control is not dictated by the caller, but by the framework, this gives it the inversion of control. Inversion of control is used to increase modularity of the program and make it extensible, meaning a user can extend the framework — usually by selective overriding, or programmers can add specialized user code to provide specific functionality. We do this because, in general, the framework code is not supposed to be modified while accepting user-implemented extensions. In other words, users can extend the framework like I said, but should not directly modify its code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7d_A0s60T5pNA-Ir" /></figure><p>So here are three examples of using different frameworks to build out a counter API. Going from left to right, these frameworks are React, Vue, and HyperApp. To get a little into what’s going on here, we can see they all have ways to store variables, in this case to keep track of the counter. They all have ways to implement methods, such as incrementing and decrementing the count variable. They all have ways to render things to the viewer, such as the counter itself along with buttons to actually increment and decrement it. So we can see why the name ‘framework’ comes into play here. Although they each have their own unique syntaxes and allow the programmer to modify its functionality, they still appear to follow some sort of rules or guidelines.</p><p>What is a library?</p><p>In computer science, a library is a collection of non-volatile resources used by computer programs, often for software development. Furthermore, it is also described as a collection of implementations of behavior written in terms of a language, that has a well-defined interface by which the behavior is invoked. The distinguishing feature is that a library is organized for the purposes of being reused by independent programs or sub-programs, and the user only needs to know the interface, and not the internal details of the library. Also, all the components of a library should proceed from an overall coherent design, and follow a set of systematic, explicit and uniform conventions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZntmSNDQ-A5Z90NaWF2x7A.png" /></figure><p>I’m sure we are all familiar with this library by now, but just in case one isn’t, this is Underscore.js, and as you can see I have just a couple examples with the filter and each method implementations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j1kUI7PK0j_xH_rMH1ywvQ.png" /></figure><p>Another common library that we should be familiar with is jQuery, and here are just a couple examples with an alert popping up when the document is loaded on the left, and on the right we have a click event with a slide up animation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rNQjWFcJsBVQHHCSHjWcJA.png" /></figure><p>So now it’s time to get into some pros and cons of frameworks. As for the pros, with efficiency, tasks that usually would take you hours and hundreds of lines of code to write can now be done in minutes with pre-built functions. Development becomes a lot easier, so if it’s easier it’s faster, and subsequently efficient. Also, widely used frameworks have big security implementations. The big advantage is the community behind it, where users become long-term testers. If you find a vulnerability or a security hole, you can go to the framework’s website and let the team know so they can fix it. In addition, as any other distributed tool, a framework usually comes with documentation, a support team, or big community forums where you can obtain quick answers.</p><p>As for the cons, I believe that the cultivation of ignorance is a major problem. If you’re using a framework and you know very little about the language behind it, you will end up just learning the framework and how it works and not exactly the language itself. For example, The way you code jQuery is different from the way you code javascript. So, if you know jQuery, it doesn’t necessarily mean you know javascript. Furthermore, the framework’s core behavior can’t be modified, meaning that when you use a framework, you are forced to respect its limits and work the way it is required. So you want to make sure you choose a framework that suits your needs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IvbzT7xwpEHWSIFzh0Yx8g.png" /></figure><p>As for the pros and cons of libraries, they are pretty straightforward. It saves you time as you do not need to develop the functionality that the library provides. Much like frameworks, another advantage of using a library is ‘proof of use’. A popular library will have been used in multiple environments and use cases. The feedback loop from this will have resulted in bugs being reported and remedied.</p><p>As for the cons, using a library means that your code is tied to that library. If at some point, you are forced to switch libraries, your code might have to undergo significant changes in order to adapt it to the new library. Also, using too many libraries can also cause problems, such as dependency conflicts, which are hard to pinpoint and fix. Also, an excess number of libraries will bloat your app by increasing its size and memory consumption.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*OUZAnLv6vEI7yhMw" /></figure><p>This brings me to my conclusion. The key difference between the two is obviously the inversion of control, meaning the way calling works with each, as demonstrated in this diagram. But, each solution has its pros and cons, and in my opinion, for achieving the best results you should probably just combine the two; because this way you will get the advantages of libraries which are solid code quality and speed, as well as the advantages of frameworks which are efficiency and support from the community.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b40bf46e4ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Time Complexity]]></title>
            <link>https://medium.com/@erhess0011/time-complexity-e83d3d10ed81?source=rss-8643d24c9e53------2</link>
            <guid isPermaLink="false">https://medium.com/p/e83d3d10ed81</guid>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Ethan Hess]]></dc:creator>
            <pubDate>Mon, 08 Oct 2018 13:16:51 GMT</pubDate>
            <atom:updated>2018-10-08T13:16:51.910Z</atom:updated>
            <content:encoded><![CDATA[<p>Time complexity is a concept in computer science that deals with the quantification of the amount of time taken by a set of code or algorithm to process or run as a function of the amount of input. In other words, time complexity is essentially efficiency, or how long a program function takes to process a given input. Furthermore, the time complexity of algorithms is most commonly expressed using the big O notation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XmhF8s8l8v2ullVvPpQovg.png" /></figure><p>To just give a quick recap on some of the most common big o notations, you can see we have our corresponding names to the actual notation itself, such as constant being O(1), logarithmic O(log n), etc. And what this does is it removes all constant factors so that the running time can be estimated in relation to <strong>N</strong>, as N approaches infinity.</p><pre>statement;</pre><p>In general you can think of it like this: say we have this single statement. This statement’s time complexity will always be <strong>Constant</strong> because the running time of the statement will not change in relation to N. For example, with arrays, looking up and assigning elements are constant time because all we would need to do is supply the index of the array and it will automatically give us whatever is at that specific index without having to look through the entire array.</p><pre>for (let i = 0; i &lt; N; i++) {<br>   statement;<br>}</pre><p>So next let’s say we have this loop with a statement inside of it. The time complexity for this loop will be <strong>Linear</strong> because the running time of the loop is directly proportional to N. So if N were to double, so would the running time. So again if we were to have an array, and this time we wanted to find, insert, or remove an element, we would have to loop through the entire length of that array to do so.</p><pre>for(i = 0; i &lt; N; i++) {</pre><pre>   for(j = 0; j &lt; N; j++) {</pre><pre>     statement;</pre><pre>   }</pre><pre>}</pre><p>So now we have two loops. This time, the time complexity for this code will be <strong>Quadratic</strong>, because the running time of the two loops is proportional to the square of N. When N doubles, the running time increases by N * N.</p><pre>function insertionSort (items) {</pre><pre>   for (var i = 0; i &lt; items.length; i++) {</pre><pre>   let value = items[i];</pre><pre>      for (var j = i - 1; j &gt; -1 &amp;&amp; items[j] &gt; value; j--) {</pre><pre>         items[j + 1] = items[j];</pre><pre>      }</pre><pre>      items[j + 1] = value;</pre><pre>   }</pre><pre>   return items;</pre><pre>}</pre><pre>const list = [54, 26, 93, 17, 77, 31, 44, 55, 20];</pre><pre>console.log(insertionSort(list)); <em>// [17, 20, 26, 31, 44, 54, 55, 77, 93]</em></pre><p>A perfect example of an algorithm with <strong>Quadratic</strong> time complexity would be an insertion sort algorithm. As we can see, we have an outer for loop and an inner for loop. In this case every iteration of the inner loop will scan and shift the entire sorted subsection of the array before inserting the next element. This is what gives insertion sort a quadratic running time (i.e., O(<em>n</em>2)).</p><pre>function binarySearch(arr, target) {</pre><pre>   let left = 0;</pre><pre>   let right = arr.length - 1;</pre><pre>   while (left &lt;= right) {</pre><pre>      const mid = left + <em>Math</em>.floor((right - left) / 2);</pre><pre>      if (arr[mid] === target) {</pre><pre>         return mid;</pre><pre>      }</pre><pre>      if (arr[mid] &lt; target) {</pre><pre>        left = mid + 1;</pre><pre>      } else {</pre><pre>        right = mid - 1;</pre><pre>      }</pre><pre>   }</pre><pre>   return -1;  </pre><pre>}</pre><p>Here is a code snippet from a binary search algorithm. Right off the bat we can see that this algorithm will have a <strong>Logarithmic</strong> Time Complexity, meaning that the running time of the algorithm is proportional to the number of times N can be divided by 2. To get a little more in depth, binary search begins by comparing the middle element of the array with the target value. If the target value matches the middle element, its position in the array is returned. If the target value is less than the middle element, the search continues in the lower half of the array. If the target value is greater than the middle element, the search continues in the upper half of the array. By doing this, the algorithm eliminates the half in which the target value cannot lie in each iteration, giving us a logarithmic time complexity</p><pre>var bruteForcePassword = function(max) {</pre><pre>   var alphabet = &#39;abcdefghijklmnopqrstuvwxyz&#39;;</pre><pre>   var findPassword = function(attempt) {</pre><pre>   if (attempt.length &gt; 0) {</pre><pre>      console.log(&#39;Trying &#39; + attempt);</pre><pre>   }</pre><pre>   if (attempt.length &lt;= max) {</pre><pre>      for (var i = 0; i &lt; alphabet.length; i++) {</pre><pre>         findPassword(attempt.concat(alphabet[i]));</pre><pre>      }</pre><pre>   }</pre><pre>};</pre><p>So next, is an example of an algorithm with <strong>Exponential</strong> time complexity. As we can see here, exponential time is usually for situations where you don’t know that much, and you have to try every possible combination or permutation. In this case we are going through the entire alphabet and trying every possible combination of letters to guess the correct password. As each combination is attempted, the time complexity will exponentially increase.</p><p>In conclusion, just remember, when you have various routes to solve a problem, it is definitely wiser to create a solution that just works first. But in the long run, you’ll want a solution that runs as quickly and efficiently as possible. And now that we have an idea on how to figure out time complexities, here are some guidelines to do just that.</p><pre>1. Does this solve the problem?  Yes ? Step 2 : keep trying<br>2. Does it cover all edge cases? Yes ? Step 3 : keep trying<br>3. Are my worst case scenarios for TC as low as possible ? Yes ? Step 4 : Step 1<br>4. Rejoice!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e83d3d10ed81" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stacks and Queues]]></title>
            <link>https://medium.com/@erhess0011/stacks-and-queues-3823774aef29?source=rss-8643d24c9e53------2</link>
            <guid isPermaLink="false">https://medium.com/p/3823774aef29</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ethan Hess]]></dc:creator>
            <pubDate>Mon, 01 Oct 2018 12:45:14 GMT</pubDate>
            <atom:updated>2018-10-01T12:45:14.174Z</atom:updated>
            <content:encoded><![CDATA[<p>What is a stack? For starters, the name <em>stack</em> comes from the analogy to a set of physical items stacked on top of each other. Such as a stack of books, or stack of paper, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DgK0Okci8kjxM8pN" /><figcaption>“assorted reading books on table” by <a href="https://unsplash.com/@morganharpernichols?utm_source=medium&amp;utm_medium=referral">Morgan Harper Nichols</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>So with that said, a stack is essentially just a data structure that holds a collection of elements, and follows the LIFO principle. The LIFO principle stands for Last In, First out, meaning that the most recently added element is the first one to be removed. So, one may ask how we go about adding and removing these said elements. That’s when the two main operations, push and pop, come in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1L20t6r0bzIVRw1b" /></figure><p>Keep in mind that these operations occur only at the top of the stack. So the push operation takes in an element and places that element at the top of stack, whereas the pop operation removes the most recently added element from the top of the stack, while also returning that element. We can see that push and pop are essential to the implementation of a stack; however, there are other operations that can be implemented as well, for example a size operation, which returns the length of the stack, or a ‘peek’ operation, which would give access to the element at the top of the stack. So really It all just depends on how the stack is implemented and used</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ef_3XSLiRTeGLBA_FENmaA.png" /></figure><p>The above demonstrates a quick implementation and use of a stack. Here we can see that this function takes in a string as the argument and uses the push operation to ‘push’ all of the letters in the stack, while the pop operation ‘pops’ each individual letter off the stack and concatenates it to an empty string, thus giving us the original, inputted string backwards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0OTEDRl3WZAdOGYx" /><figcaption>“people lining up on store” by <a href="https://unsplash.com/@zachr1992?utm_source=medium&amp;utm_medium=referral">Zach Rowlandson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Now that we’ve covered the basics of a stack let’s move on to queues. In a way, a Queue is similar to a stack in terms of being a data structure and having operations that add and remove elements. The key difference between the two is the principle that each follows. So if we recall how stack has a LIFO principle, a queue has a FIFO, meaning first in, first out. So what’s very important about this principle is that it allows the collection of elements to maintain order in the queue. A common example of a Queue would be like standing in a line. Let’s say the line is for getting into the premiere for a movie. So If I were to be the first person to get in line, then that means i would be the first person out the line and I’d be able to get some pretty nice seats for the movie; but, if I were the last person to get in the line, I’d probably end up with some bad seats and not so good of an experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*Ja4PyXtyotJ-bG0b" /></figure><p>With that said, how would we able to add and remove elements from a queue? Well with its two main operations, enqueue and dequeue. Enqueue is very similar to Stack’s push which allows us to take in an element and add it to the collection, whereas dequeue allows us to remove elements from the front of the queue, while also returning the dequeued element. So basically dequeue is the exact opposite of Stack’s pop. Following the FIFO principle, and assuming no other blocks have been dequeued just yet, we can come to the conclusion that the block at the front of the stack was the first block to be enqueued, and all the blocks before it were enqueued after. If we were to dequeue the first block, the following block will take the first position and will now be set up to be dequeued.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*701TG1svECHItwKoL2RDqg.png" /></figure><p>Here we can see a quick implementation of a queue constructor function. As you may notice, in the enqueue and dequeue methods, we see that enqueue is essentially just using an array’s native push method which I mentioned previously, and dequeue is using an array’s native shift method. Now there are other implementations of queues out there that don’t use any native methods inside of their enqueue and dequeue; however, for demonstration purposes I went ahead and used the natives.</p><p>In conclusion, stacks and queues are relatively simple when it comes to adding and removing data. Just remember the key principles that define each of the two. Stacks are LIFO (Last In First Out), while queues are FIFO (First In First Out).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3823774aef29" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hoisting variables in Javascript]]></title>
            <link>https://medium.com/@erhess0011/hoisting-variables-in-javascript-7b53d8ef825?source=rss-8643d24c9e53------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b53d8ef825</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ethan Hess]]></dc:creator>
            <pubDate>Mon, 24 Sep 2018 12:59:16 GMT</pubDate>
            <atom:updated>2018-09-24T12:59:16.579Z</atom:updated>
            <content:encoded><![CDATA[<p>What is hoisting? Essentially, hoisting is a ‘behind-the-scene’ action that an interpreter performs before executing code. Additionally, hoisting is used to explain how variables and functions are lifted to the top of a local or global scope.</p><p>To understand variable hoisting, we can break them down into its two parts: the declaration, and the assignment.</p><p>Line 1: var banana = ‘yellow’ //declaration and assignment</p><p>As we can see, the variable is both declared and assigned on the same line. However, this is how the banana variable will look once the interpreter ‘hoists’:</p><p>Line 1: var banana; //declaration gets hoisted to the top of the scope (global in this case)</p><p>Line 2: banana = ‘yellow’; //assignment of variable</p><p>If we were to try and perform an action on the banana variable before it is assigned, then we will receive an error of undefined.</p><p>Line 1: var banana;</p><p>Line 2: console.log(banana); //undefined</p><p>Line 3: banana = ‘yellow’;</p><p>How hoisting works can be very confusing at times, so just remember these couple of things:</p><p>Before any code is executed, variable and function declarations are hoisted to the top of their scope.</p><p>Functions are hoisted before variables. Meaning function declarations have priority over variable declarations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b53d8ef825" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>