<?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 Yufan Wang on Medium]]></title>
        <description><![CDATA[Stories by Yufan Wang on Medium]]></description>
        <link>https://medium.com/@yufansmail?source=rss-d92fc8e3c202------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*BN19vPbwT386xelGr9RlZA.jpeg</url>
            <title>Stories by Yufan Wang on Medium</title>
            <link>https://medium.com/@yufansmail?source=rss-d92fc8e3c202------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 15:04:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yufansmail/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[The Case For Wearing Masks to Prevent the Spread of Coronavirus]]></title>
            <link>https://medium.com/@yufansmail/the-case-for-wearing-masks-to-prevent-the-spread-of-coronavirus-cfb92daf3568?source=rss-d92fc8e3c202------2</link>
            <guid isPermaLink="false">https://medium.com/p/cfb92daf3568</guid>
            <dc:creator><![CDATA[Yufan Wang]]></dc:creator>
            <pubDate>Sat, 20 Jun 2020 08:22:33 GMT</pubDate>
            <atom:updated>2020-06-20T08:22:33.622Z</atom:updated>
            <content:encoded><![CDATA[<p>The Case For Wearing Masks to Prevent the Spread of Coronavirus</p><ol><li>Doctors and medical professional have been wearing them for decades as a proven method to prevent transmission of airborne and respiratory illnesses and preventing particulates from getting in and out</li><li>It takes minimal effort</li><li>Just do it</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cfb92daf3568" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recursion in Javascript]]></title>
            <link>https://medium.com/@yufansmail/recursion-in-javascript-2e2d3cd94d44?source=rss-d92fc8e3c202------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e2d3cd94d44</guid>
            <category><![CDATA[basics]]></category>
            <category><![CDATA[hack-reactor]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[recursion]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Yufan Wang]]></dc:creator>
            <pubDate>Wed, 31 Jan 2018 07:13:52 GMT</pubDate>
            <atom:updated>2018-01-31T20:23:58.713Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello world. I am Yufan, an <em>aspiring</em> software developer currently in my third week at <strong>Hack Reactor</strong>. In this short post I will attempt to explain the concept of recursion in Javascript, the most popular client side language in web development.</p><p>Recursion is a topic that takes many students a while to understand, and I hope to better both your understanding as well as mine by exploring a few basic examples and clearing up some key words.</p><h4><strong>First of all, what is recursion?</strong></h4><p>Recursion is a core computer science concept. There are many definitions on the internet, but basically recursion is the method of creating a function that continuously calls itself until it reaches a base case. Recursion is a method of solving problems that are usually solved iteratively. Any problem that can be solved iteratively can also be solved with recursion. A recursive function must contain a <strong>base case</strong>, which is some condition that will trigger the recursion to end, and return for every function in the <strong>call stack</strong>. To better illustrate my point, let’s take a look at a few examples.</p><h4><strong>A Simple Example</strong></h4><p>If I were to create a function to print a list of numbers one at a time, I can use either an iterative loop or recursion. The code will run exactly the same way, but the mechanism is very different.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*DGzVYGrUe9yY46sGkuSlyg.png" /><figcaption>A function to print elements iteratively, takes an array as an input and logs each element to the console.</figcaption></figure><p>A loop will print out each value up to a certain number, usually requiring setting a variable with a start value and printing out that variable, then incrementing it a desired amount after every iteration through the loop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O0ZuDkUUKNimEymWNoPXXA.png" /><figcaption>A recursive function to print out all numbers in an array.</figcaption></figure><p>Recursion turns this solution into a call stack of functions, where each call only returns one number after it reaches the end of the call stack, and returns all the way back up the chain once the base case is reached.</p><p>The base case in this code triggers once the value of ‘i’ becomes greater than the length of the array minus one. This is because array indexing starts at 0, and there is no element at the index equal to the length of the array. This event will return for every function call in the call stack. This is a bad example since we are returning nothing, but it shows that a return statement will stop the recursion once the base case is reached.</p><h4><strong>A Slightly Better Example</strong></h4><p>The previous example shows some key differences between recursive and iterative functions. We can see important elements such as the base case (in recursion), as well as the increment/decrement to a variable that eventually stops the loop (in both cases). Now, let us take a look at a more practical example of recursion in Javascript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*s0LMgqkHw8dhVS-fgso8xw.png" /><figcaption>A function that can find exponents using recursion.</figcaption></figure><p>Here is a function to calculate the result of any base number raised to the power of another number. This function uses recursion to solve exponent problems with ease. The value of ‘power’ is decremented by 1 each time the function is called, and stops recursion once the base case is reached. When the value of ‘power’ reaches 0, the number 1 is returned by the function. This return will trigger every function call going up the call stack to return as well. Every return will multiply the value of ‘base’ to the value received from the previous return. This will successfully give us the solution to any exponent problem as long as the computer can handle it. If numbers that are very large are set as the inputs, there is a risk of reaching the maximum call stack size, which will throw a ‘RangeError’ and will not give the solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*Xsf-b2uI_fV72r1_bO6sOg.png" /><figcaption>When large numbers are used as inputs to the exponent function, the console throws a ‘RangeError’, as our function has called itself too many times before being able to solve the problem.</figcaption></figure><h4><strong>Max Call Stack Size</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*rFsnIhfmJYuitsE_uRoalw.png" /><figcaption>Using this function in anything that runs Javascript will give us the max call stack size.</figcaption></figure><p>The max call stack size is the number of functions that the browser (or other software running Javascript) can have in a stack before it is not able to keep them in the stack any longer. We can create a simple function, maxCallStackSize, to find the maximum call stack size, which will give us a rough idea how many function calls we can make before reaching the max. This function is simply calling itself until it reaches an error, then returning 1. The call stack will return up the chain, adding 1 to the return of every previous function return, until it is back to the original function call. The last return will be the sum of every function call in the stack.</p><h4>Average Results:</h4><ul><li><strong>Safari (Version 11.0.3)</strong>: 31711</li><li><strong>Chrome (Version 63.0.3239.132) </strong>: 25084</li><li><strong>Firefox (Version 58.0.1)</strong>: 44511</li></ul><p>From the results above, we can see that Safari can hold about 6600 more functions in the call stack than Google Chrome, while Firefox trounces both of the other browsers with a size of 44511. This limit can change depending on many factors, and might increase or decrease with updates to the browsers, and sometimes even fluctuates during successive calls to the above function. Therefore, the call stack size should never be treated as a hard limit, or as something to build code around, as it is unpredictable and varies between browsers drastically. It is best to write code that will not reach the maximum call stack size in any of the browsers; users can be using old browsers that have maximum call stack size way below that of the up-to-date browsers shown above.</p><h3>Final Thoughts</h3><p>Recursion is a very powerful tool, and can be confusing at first. I am by no means an authority on this subject, nor am I a master of Javascript. But I hope my explanations helped at least some people get insight into the basics of recursion and how it works.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e2d3cd94d44" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>