<?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 Jason Alvarez on Medium]]></title>
        <description><![CDATA[Stories by Jason Alvarez on Medium]]></description>
        <link>https://medium.com/@jasonalvarezcoraiza?source=rss-8a56c90a1e75------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1EU1oIX-_SPWocC1yg5ndg.png</url>
            <title>Stories by Jason Alvarez on Medium</title>
            <link>https://medium.com/@jasonalvarezcoraiza?source=rss-8a56c90a1e75------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 11:25:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jasonalvarezcoraiza/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[Dynamic Programming, you may have seen it before (ha ha)]]></title>
            <link>https://jasonalvarezcoraiza.medium.com/dynamic-programming-you-may-have-seen-it-before-ha-ha-a00a9f73b9e8?source=rss-8a56c90a1e75------2</link>
            <guid isPermaLink="false">https://medium.com/p/a00a9f73b9e8</guid>
            <category><![CDATA[dynamic-programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[memoization]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tabulation]]></category>
            <dc:creator><![CDATA[Jason Alvarez]]></dc:creator>
            <pubDate>Tue, 15 Dec 2020 11:24:59 GMT</pubDate>
            <atom:updated>2021-01-12T04:00:15.975Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*5crxRDU2Q0tySWIc" /><figcaption>Image from <a href="https://unsplash.com/photos/odxB5oIG_iA">https://unsplash.com/photos/odxB5oIG_iA</a></figcaption></figure><p>Apart from being an acceptable way to get rushes of serotonin, dynamic programming is a way to cut down on time complexity.</p><p>So what is Dynamic Programming? Dynamic Programming is a practice where you break up a problem that is dependent on smaller problems and then optimize the time complexity of those problems to improve the time complexity of the overall problem.</p><p>Time complexity refers to the amount of time the program needs to run. There is a range of terms for the varying time complexities. The best one and shortest is linear time, which has one iteration per input. To be clear, if you have an array (a list) and you want to iterate through each one to console log them, that would be linear time.</p><pre>const nums = [1,2,3,4];<br>    nums.map(num =&gt; {<br>       console.log(num);<br>    });</pre><p>Let&#39;s use a more complicated example, the infamous Fibonacci sequence. Dynamic programming varies in the amount it crushes downtime complexity depending on the original complexity. As such, I recommend writing a brute force solution first and then work on incorporating dynamic programming practices. The Fibonacci sequence is a list of numbers that follows a pattern where the previous and number previous to that one add together to equal the next one.</p><pre>//fibonacci sequence<br>    const fibonacci = [1,1,2,3,5,8,13,21,34,55,89]; //goes on forever</pre><p>The general formula for determining the time complexity when incorporating dynamic programming is the number of unique calculations * time taken per calculation.</p><p>For the Fibonacci sequence, the brute force solution for finding the number at an nth place in the Fibonacci sequence goes something like this:</p><pre>const fibonacci = (n) =&gt; {<br>    if (n &lt;= 2) {<br>        return 1;<br>    }<br>    return fibonacci(n - 1) + fibonacci(n - 2);<br>};</pre><p>This implementation of finding the nth term in the Fibonacci sequence is done with recursion and has a time complexity of 2^n or exponential time.</p><p>This can be cut down through the implementation of dynamic programming and then you’ll hopefully get you fix of serotonin.</p><h3>Implementation:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*0z_R_7P5wNyMc4Qr.png" /><figcaption>Image found here: <a href="https://www.reddit.com/r/ProgrammerHumor/comments/8nojqc/dynamic_programming/">https://www.reddit.com/r/ProgrammerHumor/comments/8nojqc/dynamic_programming/</a></figcaption></figure><h4>Memoization</h4><p>One way to incorporate dynamic programming is through memoization. Memoization is where you store calculations that you plan on repeating so that you don’t have to recalculate them again later. This cuts down the time our program takes to run because it takes less time to get our stored values than it does to recalculate.</p><p>So, you’ll notice that in the Fibonacci example, we are repeating the same calculations when we call it with a value over 3. Here’s an example of the function call with the number 7:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*rA7rvNJUY2K926k0HZdU4A.png" /><figcaption>Node graph of the 7th term of the Fibonacci Sequence</figcaption></figure><p>In the graph above, the right side of the graph can be seen as a part of the left one. This means that we are recalculating this part all over again. Sure it may not take too long since our computer can handle it, but when the number becomes exceedingly high, the program will drastically slow down. So, how do we incorporate dynamic programming into the previous solution?</p><p>Since we want to make our program as fast as possible, we should have a way of storing and grabbing values from that storage in the fastest way possible. In javascript, we’d use an object since they store using key-value pairs that can be accessed in linear time through the key.</p><pre>const fibonacci = (n, memo = {}) =&gt; {<br>    if(memo[n]){<br>        return memo[n];<br>    }<br>    if (n &lt;= 2) {<br>        return 1;<br>    }</pre><pre>    return memo[n] = fibonacci(n - 1, memo) + fibonacci(n - 2,memo);<br>};</pre><p>In the code above, there is a new parameter called memo, short for memoization. This object will function as storage that can be accessed in linear time using the nth term as the key. This causes the calculations to be cut down since we don’t have to recalculate any values that have already been calculated and stored in memo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*HW0L_cx7QavpUsXV.png" /><figcaption>Image from: <a href="https://me.me/i/memoization-recursive-function-dp-is-my-kink-dynamic-programming-e142428ab6c34d598bb565f5e1f51111">https://me.me/i/memoization-recursive-function-dp-is-my-kink-dynamic-programming-e142428ab6c34d598bb565f5e1f51111</a></figcaption></figure><p>To recap, you use memorization to remember repeated calculations, make your code run faster, drown in serotonin, and make the world a better place.</p><h4>Tabulation</h4><p>Some of you may still be craving that need for speed though. That’s understandable since we’re still recursing with memoization, so let’s try out tabulation.</p><p>Unlike memoization, tabulation involves tackling the problem from the base to the top. For instance, in memoization we begin at the nth term and work our way down to the first or second terms that then populate every term up till the nth term. When using tabulation, we start by looking at the first term and building our way up to the nth term from there.</p><p>Since we know how the Fibonacci sequence starts off as 0,1, we can make an array off that and consistently push the new values into it and pull out the nth value using the index. Also, for those of you wondering, I start off the array at 0 because the Fibonacci sequence technically starts off at zero but it&#39;s unnecessary to include in the sum since anything plus zero is still zero.</p><p>Anyway, here’s the code for our tabulation:</p><pre>const fibonacci = (n) =&gt; {<br>    const tab = [0,1];<br>    for (let i = 2; i &lt;= n; i++) {<br>        tab[i] = tab[i - 1] + tab[i - 2];<br>    }</pre><pre>    return tab[n];<br>};</pre><p>Now, you may notice that there is no recursion in this method. That means that we will never reach a maximum call stack depth since we never call the same function again.</p><h3>Conclusion</h3><p>So, to clear all that information up, dynamic programming is just a practice that helps cut down on time complexity/make your program run faster. Welp, hope you got your hit of serotonin for the day.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a00a9f73b9e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Call, Apply, and Binding in JS: The Art of Being Overly Fancy]]></title>
            <link>https://medium.com/swlh/call-apply-and-binding-in-js-the-art-of-being-overly-fancy-7aceddae88f7?source=rss-8a56c90a1e75------2</link>
            <guid isPermaLink="false">https://medium.com/p/7aceddae88f7</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[binding]]></category>
            <category><![CDATA[objects]]></category>
            <category><![CDATA[function]]></category>
            <category><![CDATA[problem-solving]]></category>
            <dc:creator><![CDATA[Jason Alvarez]]></dc:creator>
            <pubDate>Fri, 20 Nov 2020 20:44:27 GMT</pubDate>
            <atom:updated>2020-11-23T08:22:25.707Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GKZ3xdMyBf3G0M63BTt61w.jpeg" /><figcaption>Find this image at pexels at <a href="https://www.pexels.com/photo/sea-nature-sunset-water-119562/">https://www.pexels.com/photo/sea-nature-sunset-water-119562/</a></figcaption></figure><p>Alright, so you wanna be fancy or you saw something about Call, Apply and Bind and were wondering what that was all about. In simple terms, Call, Apply and Bind are methods that can be used on or with functions and objects that allow you to access the object&#39;s properties within the function.</p><p>Now an overview on JS objects, which is what we’ll be working with since that’s what call, apply and bind are supposed to be used on. So, a JS object is something called a data structure, which is an entry-level of fancy that basically serves to hold data in a way that is easy to read and work with. Now, to explain how call, apply and bind will interact with JS objects. It basically boils down to a way to add objects to function calls. Function calls normally have to take in parameters, but with these methods, you can use function calls without having to change your functions, you know if you’re scared to break something. Call and Apply can be assumed as to what they would do, but to be more explicit about it, the call and apply methods are applied to a function to bind an object&#39;s properties to the functions this.</p><p>Anyway, I know the first thing I look for in a technical blog is the syntax or an example, so to get that out of the way, but don’t worry about not knowing how it works yet, I’m getting there, and here’s what our end product will look like:</p><pre>let me = {<br> name: &quot;Jason Alvarez&quot;,<br> hobbies: [&quot;Traditional Art&quot;, &quot;Digital Art&quot;, &quot;Game Development&quot;],<br> languages: [&quot;C++&quot;, &quot;C#&quot;, &quot;React&quot;, &quot;CSS&quot;, &quot;HTML&quot;, &quot;Javascript&quot;]<br>}<br>let hire = function(salary) {<br> return `${this.name}, you&#39;re hired with a salary of ${salary}`;<br>}<br>console.log(hire.call(me, &quot;120k&quot;));<br> // &quot;Jason Alvarez, you&#39;re hired with a salary of 120K&quot;<br>let learnedLanguage = function(...languages){<br> this.languages = this.languages.concat(languages);<br> const languagesString = languages.join(&quot; and &quot;);<br> //Places the word &#39;and&#39; in between the languages<br> const knownLanguages = this.languages.join(&quot; and &quot;) <br> return `${this.name}, You&#39;ve learned ${languagesString}, congratulations! You now know<br>${knownLanguages}`;<br>}<br>console.log(learnedLanguage.apply(me, [&quot;Python&quot;, &quot;React Native&quot;]));<br>//Jason Alvarez, You&#39;ve learned Python and React Native, congratulations! You now know C++<br>and C# and React and<br>// CSS and HTML and Javascript and Python and React Native<br>function addHobby(...newHobbies){<br> this.hobbies = this.hobbies.concat(newHobbies);<br> const hobbiesStr = this.hobbies.join(&quot; and &quot;);<br> const newHobbiesStr = newHobbies.join(&quot; and &quot;);<br> return `${this.name}&#39;s hobbies are ${hobbiesStr}. He&#39;s recently picked up<br>${newHobbiesStr}.`;<br>}<br>const newHobby = addHobby.bind(me);<br>console.log(newHobby(&quot;Blog writing&quot;, &quot;Studying Art History&quot;));<br>//Jason Alvarez&#39;s hobbies are Traditional Art and Digital Art and Game Development and Blog<br>writing and<br>//Studying Art History. He&#39;s recently picked up Blog writing and Studying Art History.</pre><h3>Call() :</h3><p>The call method in the example is being applied to a function, hire(), and passing it the me object and an argument of salary.</p><pre>let me = {<br> name: &quot;Jason Alvarez&quot;,<br> hobbies: [&quot;Traditional Art&quot;, &quot;Digital Art&quot;, &quot;Game Development&quot;],<br> languages: [&quot;C++&quot;, &quot;C#&quot;, &quot;React&quot;, &quot;CSS&quot;, &quot;HTML&quot;, &quot;Javascript&quot;]<br>}<br>let hire = function(salary) {<br> return `${this.name}, you&#39;re hired with a salary of ${salary}`;<br>} <br>console.log(hire.call(me, &quot;120k&quot;));<br>// &quot;Jason Alvarez, you&#39;re hired with a salary of 120K&quot;</pre><p>The object being passed in has three properties (name, age, and languages), which can be accessed with the this keyword. We can see that I’m accessing my name with this.name. As for the characters surrounding this.name, that’s simply due to string interpolation that allows me to use variables and keywords within a string. The second argument of the function call serves as the argument for the hire function, which is printed out the same way my name is, through the string interpolation. So, the call will return a string starting with my name and continuing onto saying that I’ve been hired with a salary of at least 120k (ah, you’re too kind).</p><h3>Real-world applications:</h3><p>You may have noticed that I am not using the original object, that’s because I can use the this keyword! One must simply reassign a property of the object through this to its desired value. Let me demonstrate by slightly changing the hire function:</p><pre>let me = {<br> name: &quot;Jason Alvarez&quot;,<br> hobbies: [&quot;Traditional Art&quot;, &quot;Digital Art&quot;, &quot;Game Development&quot;],<br> languages: [&quot;C++&quot;, &quot;C#&quot;, &quot;React&quot;, &quot;CSS&quot;, &quot;HTML&quot;, &quot;Javascript&quot;]<br>}<br>let hire = function(salary) {<br> this.name = this.name+salary<br> return `${this.name}, you&#39;re hired with a salary of ${salary}`;<br>}<br>console.log(hire.call(me, &quot;120k&quot;));<br> // &quot;Jason Alvarez120k, you&#39;re hired with a salary of 120K&quot;</pre><p>This will mutate my original object to have a key-value pair of name: &quot;Jason Alvarez120k&quot;, which allows for far more flexibility in the real world, as you can make a function that changes a name that is not constricted to a single object. However, that is not a requirement for real-world applications. If you wanted, you could use a slightly altered version of this code to say “Pokemon-name, I chose you.” if you’re trying to make the next pokemon game. (Also is it just me or has pokemon become staler?) One last point on call, as well as apply, which we’ll get to in a second. You may have noticed that the call method is being performed on functions with the keyword function instead of arrow functions. That is because arrow functions do not have a this of their own, thus returning incorrect values like NaN or undefined whenever you attempt to do something with them within a function. So keep the function keyword.</p><h3>Apply() :</h3><p>The apply method works just like the call method with one difference, instead of taking multiple arguments in the function call, it takes an array. Here’s an example that builds off the last example :</p><pre>let me = {<br> name: &quot;Jason Alvarez&quot;,<br> hobbies: [&quot;Traditional Art&quot;, &quot;Digital Art&quot;, &quot;Game Development&quot;],<br> languages: [&quot;C++&quot;, &quot;C#&quot;, &quot;React&quot;, &quot;CSS&quot;, &quot;HTML&quot;, &quot;Javascript&quot;]<br>}<br>let learnedLanguage = function(...languages){<br> this.languages = this.languages.concat(languages);<br> const languagesString = languages.join(&quot; and &quot;);<br> //Places the word &#39;and&#39; in between the languages<br> const knownLanguages = this.languages.join(&quot; and &quot;);<br> return `${this.name}, You&#39;ve learned ${languagesString}, congratulations! You now know<br>${knownLanguages}`;<br>}<br>console.log(learnedLanguage.apply(me, [&quot;Python&quot;, &quot;React Native&quot;]));<br>//Jason Alvarez, You&#39;ve learned Python and React Native, congratulations! You now know C++<br>and C# and React and<br>// CSS and HTML and Javascript and Python and React Native</pre><p>In this example, we develop a new function that adds languages to my list of known languages and returns a string saying that I know such and such, having recently learned whatever was passed in as an argument.</p><h3>Real-world application:</h3><p>If you have an array of data that you want to add without accidentally breaking an existing method, this would be the way to go. Of course, you could use call if you passed a rest parameter. However, there are other ways to perform such a function. I would suggest making a new method within your object, as to not break any existing methods while keeping the code condensed within the object. In reality, there’s almost always another way to handle a problem and it’s up to the developer to determine what the best solution is for their circumstance.</p><h3>Bind() :</h3><p>Finally, as for bind, this one is far more elegant, in my opinion. Now, time for you to agree with me through an example:</p><pre>let me = {<br> name: &quot;Jason Alvarez&quot;,<br> hobbies: [&quot;Traditional Art&quot;, &quot;Digital Art&quot;, &quot;Game Development&quot;],<br> languages: [&quot;C++&quot;, &quot;C#&quot;, &quot;React&quot;, &quot;CSS&quot;, &quot;HTML&quot;, &quot;Javascript&quot;]<br>}<br>function addHobby(...newHobbies){<br> this.hobbies = this.hobbies.concat(newHobbies);<br> const hobbiesStr = this.hobbies.join(&quot; and &quot;);<br> const newHobbiesStr = newHobbies.join(&quot; and &quot;);<br> return `${this.name}&#39;s hobbies are ${hobbiesStr}. He&#39;s recently picked up<br>${newHobbiesStr}.`;<br>}<br>const newHobby = addHobby.bind(me);<br>console.log(newHobby(&quot;Blog writing&quot;, &quot;Studying Art History&quot;));<br>//Jason Alvarez&#39;s hobbies are Traditional Art and Digital Art and Game Development and Blog<br>writing and<br>//Studying Art History. He&#39;s recently picked up Blog writing and Studying Art History.</pre><p>First things first, you’ll see that addHobby is a function declaration instead of a function expression. The reason for this is because bind returns a function and we’ll need to store it so I opted to not bother assigning it to a variable. As for bind’s syntax, it starts out with the function it wants to bind an object with. After that, bind is called and passed an object as an argument. This will create a new function object with the name of the variable we are assigning the bound function to, in this case, newHobby. When calling newHobby , we simply pass it whatever arguments we want since the function is already bound to the object.</p><h3>Send off :</h3><p>Some small pointers before you hop off to refresh what you’ve just read.</p><p><strong>Call</strong></p><ul><li>takes in an object to be bound followed by single arguments(not an array)</li></ul><p><strong>Apply</strong></p><ul><li>takes in an object to be bound followed by an array of elements</li></ul><p><strong>Bind</strong> :</p><ul><li>Called on an existing function</li><li>Takes an argument of the object you want to bind the function to</li><li>Returns a copy of the function called on with the object bound to it</li><li>Binding an object to a function allows you to call that function without passing it the object whose properties you want to use</li></ul><p><strong>This keyword</strong> :</p><ul><li>It’s cool(don&#39;t be a square dude)</li><li>Allows us to access an object’s properties without a reference to a specific object</li><li>There’s more to the this keyword but that has to do with classes and the global reference which go way out of scope for this piece. You’ve been reading long enough already. So now you know what Bind, Call and Apply do, and hopefully, I’ll be making over 120k one day. GoodBye!</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7aceddae88f7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/call-apply-and-binding-in-js-the-art-of-being-overly-fancy-7aceddae88f7">Call, Apply, and Binding in JS: The Art of Being Overly Fancy</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>