<?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 Kah Yap on Medium]]></title>
        <description><![CDATA[Stories by Kah Yap on Medium]]></description>
        <link>https://medium.com/@kahyap13?source=rss-c5ab8c5623d1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4-999jrlB2tx5fe_Zwutsw.jpeg</url>
            <title>Stories by Kah Yap on Medium</title>
            <link>https://medium.com/@kahyap13?source=rss-c5ab8c5623d1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 19:13:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kahyap13/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[var let const]]></title>
            <link>https://medium.com/@kahyap13/var-let-const-dbfdba292415?source=rss-c5ab8c5623d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbfdba292415</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kah Yap]]></dc:creator>
            <pubDate>Mon, 24 Jun 2019 16:52:26 GMT</pubDate>
            <atom:updated>2019-06-24T16:52:26.875Z</atom:updated>
            <content:encoded><![CDATA[<p>Just started programming? Educational programming websites using var in their functions? Friends telling you to use let and const without explaining why?</p><p>Knowing the difference between var, let, and const is a little confusing at first especially when they all seem to do the same thing. However there are small differences in each that could cause you endless bugs if misused</p><p>Var doesn’t respect block scope. Lets take a look at what I mean by that</p><pre>var test = function(){<br>  var x = true;</pre><pre>  if(x) {<br>    var y = true;<br>  }</pre><pre>  console.log(y)<br>}</pre><pre>test() // will console log true</pre><p>Even though the variable y is within the if condition’s block scope, it can still be accessed outside because it was used with var variable. Although var doesn’t respect the block scope, it will respect the function’s scope meaning that if you try to console log “y” outside of the function it will give you an error</p><p>The reason I’d recommend you from using var is that it is less secure and might cause bugs down the line since variables with var is more accessible throughout our code which is something we don’t want. We want our code to be more private</p><p>let</p><p>With ES6 “let” is the preferred way to store a variable. My general rule of thumb is when in doubt use “let”. But generally you use let when you plan on having the variable change such as when using a for loop or doing math</p><pre>function count() {<br>  for(let i = 0; i &lt; 10; i++) {<br>    console.log(i)<br>  }<br>  console.log(i)<br>}</pre><pre>count()</pre><p>You wouldn’t be able to console log the “i” variable because the “i” is only within the for the loop. This is good practice because you don’t want outside code from influencing your scope</p><p>const</p><p>With ES6 “const” is also introduced as a way to keep your variables from being reassigned. Lets take a look at this example</p><pre>// x will be able to get reassigned to 2<br>let x = 1;<br>x = 2;</pre><pre>// y will not be able to get reassigned because it is a const<br>const y = 1;<br>y = 2;</pre><p>A “const” can’t be reassigned, however that doesn’t mean that it is immutable</p><p>Hunh?</p><pre>const arr = [1, 2, 3]<br>arr.pop()<br>console.log(arr) // [1, 2]</pre><pre>const arr = 1;<br>arr = 2; // this will throw us an error</pre><p>I’d highly recommend to use “let” over “var” and when it is suitable use “const” over “let”</p><p>I hope this was helpful in understanding some of the differences between “var”, “let”, and “const”!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbfdba292415" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recursion Part 1]]></title>
            <link>https://medium.com/@kahyap13/recursion-part-1-a9ef072e00d9?source=rss-c5ab8c5623d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9ef072e00d9</guid>
            <category><![CDATA[recursion]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kah Yap]]></dc:creator>
            <pubDate>Mon, 17 Jun 2019 20:05:41 GMT</pubDate>
            <atom:updated>2019-06-17T20:05:41.301Z</atom:updated>
            <content:encoded><![CDATA[<p>What is recursion?</p><p>A recursion is a function that calls itself until it doesn’t?</p><p>Okay, I hear it but I don’t get it so can you show me some code?</p><pre>let countDown = num =&gt; {<br>  console.log(num)<br>  countDown(num - 1)<br>}</pre><pre>countDown(10)</pre><p>Whats happening here is that you are writing an ES6 function called countDown and we are passing in 10 for our argument parameter. It’ll print out 10 then call countDown but with num subtracted by 1 which is 9.</p><p>Do you see whats about to happen? Let us go through it one more time after the first recursive call. countDown is now given an argument of 9 and will print out 9 then call countDown again but with our num 9 subtracted by 1.</p><p>If you run this code you are going to have a bad time because it’ll never stop since there was never a break case to tell our recursive function to stop. To do that simply provide an if condition</p><pre>let countDown = num =&gt; {<br>  if(num === 0) return;  <br>  console.log(num)<br>  countDown(num - 1)<br>}</pre><pre>countDown(10)</pre><p>Because of our if condition, the moment we our recursive function is given a 0 as an argument it will stop.</p><p>This blog will get updated with more information later on but I hope you were able to understand recursion in a basic form.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9ef072e00d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Two Sum]]></title>
            <link>https://medium.com/@kahyap13/two-sum-f89b1ab91946?source=rss-c5ab8c5623d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/f89b1ab91946</guid>
            <category><![CDATA[two-sum]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kah Yap]]></dc:creator>
            <pubDate>Mon, 10 Jun 2019 07:01:12 GMT</pubDate>
            <atom:updated>2019-06-10T07:01:12.385Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*5bVhbdkf91TzRLBFeJNYPw.gif" /></figure><p>So you’re taking your first step on solving algorithms on LeetCode hunh? Great job! You just finished it however you might be getting a message saying that you are only solving it faster than 25% of the submissions. So whats going on?</p><p>Chances are you solved it through the brute force method which is not bad, you were able to solve the problem, however being able to write code with efficiency is extremely important</p><p>Heres a solution I came up with without having to write a loop within a loop</p><pre>var twoSum = function(nums, target){<br>    if(nums.length === 2) return [0, 1];<br>    <br>    let hashMap = {};<br>    <br>    for(let i = 0; i &lt; nums.length; i++) {<br>        let find = target - nums[i];<br>        let found = hashMap[find]<br>        if(found !== undefined) {<br>            return [found, i]<br>        } else {<br>            hashMap[nums[i]] = i;<br>        }<br>    }<br>};</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*1wxvB2IssuYP-AbG-t8Qvg.gif" /><figcaption>Its time to break it down!</figcaption></figure><pre>if(nums.length === 2) return [0, 1];</pre><p>Whats happening here on the first if statement is that if the length of the array is 2 then you just return [0, 1] because those will be the only number to add up to the target</p><pre>let hashMap = {};</pre><p>We then created a hash where we will be storing the numbers that we iterate through</p><pre>for(let i = 0; i &lt; nums.length; i++) {<br>        <br>}</pre><p>Now we want to iterate through the given array by writing a for loop</p><pre>let find = target - nums[i];<br>let found = hashMap[find]</pre><p>Inside the for loop we want to write a variable named “find” which will store the number that we want to look for inside the array</p><p>To do that we take our target number and subtract it by the number at the current iteration. For example, if your target is 9 and your current number is 3, you subtract 3 from 9 giving you 6 which will then be the number you are looking for</p><p>Once we have found the number we will see if it exists within the hashMap we created earlier</p><pre>if(found !== undefined) {<br>  return [found, i]<br>} else {<br>  hashMap[nums[i]]<br>}</pre><p>Now heres the final step</p><p>During each iteration we will see if the key we need exists in our hashMap. If it does then we return [found, i] because that will be the 2 numbers that add up to our target</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*uUOCduJDqkm6otu3cpD60g.gif" /><figcaption>Wheres the key??</figcaption></figure><p>If the key doesn’t exist then we simply create it and eventually through our loop we will be able to find a key that will be able to sum with our current iteration to our target</p><p>I hope this read was able to help with solving twoSum without using a brute force method. Solving algorithms is always difficult when you first start especially when the correct answer might not be enough. However with more and more practice it does get easier because you’ll be able to recognize similar patterns and problems that you’ve faced before. Best of luck programmers!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*cmHFdtnAuPZavbUBQpE0nQ.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f89b1ab91946" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Slice n’ Splice!]]></title>
            <link>https://medium.com/@kahyap13/slice-n-splice-d6594d079e6c?source=rss-c5ab8c5623d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6594d079e6c</guid>
            <category><![CDATA[slice]]></category>
            <category><![CDATA[splice]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kah Yap]]></dc:creator>
            <pubDate>Wed, 29 May 2019 05:47:36 GMT</pubDate>
            <atom:updated>2019-05-29T06:24:02.979Z</atom:updated>
            <content:encoded><![CDATA[<p>Wait, do we use slice or splice?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*qf-gHQllqBytQz8fRRuAcQ.gif" /><figcaption>I don’t remember…</figcaption></figure><p>A friend of mine once told me the best way of remembering this is that splice sounds scarier than slice because splice is destructive</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*xm1xjohkmkQz4q8LRqzV2A.gif" /></figure><p>So what does it mean for splice to be destructive?</p><p>Well when something is destructive it means that it’ll change the original object. Lets take a look at a few code down below to get a better understanding of this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*awjhQhqkpldNGCuPPR-2kw.gif" /></figure><pre>let arr = [1, 2, 3]</pre><pre>const slice = arr =&gt; {<br>  return arr.slice(0, 1)<br>}</pre><pre>slice(arr) // this will return 1 because that is whats being removed</pre><pre>console.log(arr); // will print out the original arr [1, 2, 3]</pre><pre>let arr = [1, 2, 3]</pre><pre>const splice = arr =&gt; {<br>  return arr.splice(0, 1)<br>}</pre><pre>splice(arr) // this will also return 1</pre><pre>console.log(arr); // however this will only print out [1, 2] because the original arr was altered from splice</pre><p>I hope you were able to remember the difference between slice and splice!</p><p>slice === non destructive</p><p>splice === destructive // scary stuff</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6594d079e6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginners Interview Question]]></title>
            <link>https://medium.com/@kahyap13/beginners-interview-question-891c3691a950?source=rss-c5ab8c5623d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/891c3691a950</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kah Yap]]></dc:creator>
            <pubDate>Thu, 28 Feb 2019 18:14:55 GMT</pubDate>
            <atom:updated>2019-03-01T20:38:06.977Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*y1wCAF0nlJxSFWnvG2Xexw.gif" /></figure><p>What will be the output of both console.log?</p><pre>console.log(0.1 + 0.2);<br>console.log(0.1 + 0.2 === 0.3);</pre><p>If you answered “0.3” for the first console.log and “true” for the second console.log you are incorrect!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*JvaUgEtkcSrKm_r4Q_1PWA.gif" /><figcaption>Hunh??</figcaption></figure><p>The first console.log will be “0.30000000000000004” because of the way JavaScript handles floats, therefore the second console.log will be “false”</p><p>JavaScript is filled with Gotchas that kind of defy common logic, to really blow your mind check out this link below that will make you say “Wat?”</p><p><a href="https://www.destroyallsoftware.com/talks/wat">Wat</a></p><p>Write a function that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*f0Dgjb93knxfojB0cEzwUw.gif" /></figure><p>How was it? Were you able to solve it? If not thats okay, you’ll just need to practice a bit more and you’ll be ready the next time you are asked this question! Heres a simple solution to FizzBuzz</p><pre>for (let i = 0; i &lt;= 100; i++) {<br>    if (i % 15 == 0) {<br>      console.log(&quot;FizzBuzz&quot;);<br>    } else if (i % 3 == 0) {<br>      console.log(&quot;Fizz&quot;);<br>    } else if (i % 5 == 0) { <br>      console.log(&quot;Buzz&quot;);<br>    } else {<br>      console.log(i);<br>    } <br>  }</pre><p>We wrote a for loop to iterate through the numbers starting from 1 until 100 to print out the number in every iteration. However we needed to write conditions for specials numbers that have to be replaced by their special word.</p><p>The reason why we wrote the first if statement as 15 is because it was the product of 3 and 5, so any numbers that can be divided evenly by 15 is both a multiple of 3 and 5. Another reason why we had to write 15 first is that the moment we satisfy one of the conditions, the if statement will stop and will output our answer. Because of this, if we put 15 on the bottom and 3 on top, we will never be able to print out “FizzBuzz” and print out “Fizz” instead.</p><p>If you solved this problem in a different way don’t worry about it! The wonders of code is that there are MANY different ways to solve a problem</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*czAxVcyHtqgYzWogwelG6A.gif" /><figcaption>Don’t let Fizz get to you!</figcaption></figure><p>Heres a great interview question that I found on reddit (<a href="https://www.reddit.com/r/javascript/comments/7535tm/amazon_web_developer_loop_timeout_interview/">https://www.reddit.com/r/javascript/comments/7535tm/amazon_web_developer_loop_timeout_interview/</a>)</p><p>What is the output of the following code?</p><pre>const arr = [10, 12, 15, 21];<br>for (var i = 0; i &lt; arr.length; i++) {<br>    setTimeout(function() {<br>        console.log(&#39;Index: &#39; + i + &#39;, value: &#39; + arr[i]);<br>    }, 3000);<br>}</pre><p>This might seem simple to a few of us, maybe even too simple… Clearly its got to be this right?</p><pre>Index: 0, value: 10<br>Index: 1, value: 12<br>Index: 2, value: 15<br>Index: 3, value: 21</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*qXgXsygQluPr-q1lJRex5w.gif" /></figure><p>Well guess what! it was a trick question! The actual answer is</p><pre>Index: 4, value: undefined<br>Index: 4, value: undefined<br>Index: 4, value: undefined<br>Index: 4, value: undefined</pre><p>The reasoning is because of the setTimeout, the console.log will not run until 3 seconds later and then the for loop would’ve finished already therefore the index will now be at 4 and the value will be undefined because there is no index of 4</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*-6NWV45_BmgvFfoUSsdu3w.gif" /></figure><p>What is a closure?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*3p8t-J3Hi3_fSu6UbjTGJg.gif" /></figure><p>Heres the google definition :</p><p>A <strong>closure</strong> is a feature in <strong>JavaScript</strong> where an inner function has access to the outer (enclosing) function’s variables — a scope chain. … it has access to its own scope — variables defined between its curly brackets. it has access to the outer function’s variables. it has access to the global variables.</p><p>A closure is basically when an inner function has access to variables outside of its scope</p><p>Sure, sure… so what?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*EnHxSKEYK2Y5JBXT9lrOjA.gif" /></figure><p>That means your code will be more private and have its own “global variable” meaning that other code won’t be able to change it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*S7BgxD4J2MRPi03rKY29kw.gif" /><figcaption>What?</figcaption></figure><p>Heres an example of how global variables are easily influenced</p><pre>let count = 5;</pre><pre>const addCount = () =&gt; {<br>  count++<br>  console.log(&quot;After adding&quot;, count)<br>}</pre><pre>const multiplyCount = () =&gt; {<br>  count *= 2<br>  console.log(&quot;After multiply&quot;, count)<br>}</pre><pre>addCount() // will console out 6<br>multiplyCount() // will console out 12</pre><p>Notice how we have a global variable named count that is set to 5. Our addCount() will increase the count to 6, then our multiplyCount() will double it . Oh no! Theres got to be a better way of keeping count of each of our functions! Well there is, this is where closure comes in. Check out the example below for a better understanding (shoutout to Jane for showing us this example)</p><pre>const fruitStand = fruit =&gt; {<br>  let count = 0;<br>  return () =&gt; {<br>    count ++;<br>    return `Ive sold ${count} ${fruit}`<br>  }<br>}</pre><pre>const orange = fruitStand(&quot;orange&quot;)<br>const watermelon = fruitStand(&quot;watermelon&quot;)</pre><pre>const fruitCount = () =&gt; {<br>  orange()<br>  console.log(orange())<br>  console.log(watermelon())<br>}</pre><pre>fruitCount()</pre><p>The above code will console out “Ive sold 2 orange” and “Ive sold 1 orange”. Lets run through this code step by step</p><pre>const fruitStand = fruit =&gt; {<br><br>}</pre><p>We first created a function called “fruitStand” and gave it an argument of “fruit” (this will be important later)</p><pre>const fruitStand = fruit =&gt; {<br>  let count = 0;<br><br>}</pre><p>Then we created a variable “count” which can be accessed by the inner function that we will later write</p><pre>const fruitStand = fruit =&gt; {<br>  let count = 0;<br>  return () =&gt; {<br>    count ++;<br>    return `Ive sold ${count} ${fruit}`<br>  }<br>}</pre><p>Finally we finished out closure by writing an inner anonymous function that will increment the “count” variable and return how many fruit you’ve sold. Our closure is now completed so lets see its magic</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fgiant.gfycat.com%2FTalkativePertinentFinnishspitz.webm&amp;src=https%3A%2F%2Fgfycat.com%2Fifr%2FTalkativePertinentFinnishspitz&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=gfycat" width="1920" height="1078" frameborder="0" scrolling="no"><a href="https://medium.com/media/977faa51ae717ae4747d5349845a13d5/href">https://medium.com/media/977faa51ae717ae4747d5349845a13d5/href</a></iframe><pre>const orange = fruitStand(&quot;orange&quot;);<br>const watermelon = fruitStand(&quot;watermelon&quot;);</pre><p>Lets pass in a string argument to fruitStand and saved it to a variable name</p><pre>const fruitCount = () =&gt; {<br>  orange()<br>  console.log(orange())<br>  console.log(watermelon())<br>}</pre><pre>fruitCount()</pre><p>Now lets create a function “fruitCount” so we can run both the orange and watermelon at the same time and it’ll console out “Ive sold 2 orange” and “Ive sold 1 watermelon”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/371/1*2W4MNbHxKR7l4O3o4MWh7Q.gif" /></figure><p>Do you see how amazing closure was?? Now we can keep track of how many fruits of each type we’ve sold!</p><p>I hope I didn’t lose any of you here, but if I did I apologize and thats okay, there are many resources out there that will help you get ready for an interview such as <a href="https://guide.freecodecamp.org/miscellaneous/interview-questions-for-junior-front-end-web-developers/">https://guide.freecodecamp.org/miscellaneous/interview-questions-for-junior-front-end-web-developers/</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*P8gHUgLMskVboduPiMD42A.gif" /><figcaption>Till next time!</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=891c3691a950" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Garbage Collection]]></title>
            <link>https://medium.com/@kahyap13/garbage-collection-75006fadad3b?source=rss-c5ab8c5623d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/75006fadad3b</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Kah Yap]]></dc:creator>
            <pubDate>Thu, 07 Feb 2019 17:03:14 GMT</pubDate>
            <atom:updated>2019-02-07T17:03:14.646Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*9fGFp-XQpHouQB6-o71vwA.gif" /><figcaption>Remember to recycle :)</figcaption></figure><p>Garbage collection is a form of automatic memory management. The garbage collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program</p><p>TLDR: Garbage collection frees up space in our program</p><p>Memory management in JavaScript is performed automatically whenever we create primitives, objects, functions. Sounds great! so lets free up some space in our program! I mean more space === faster program right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*SAmQ0ceksLi88YLSHe_8Og.gif" /></figure><p>The thing is we don’t actually have to do anything for our program to use garbage collection, it is performed automatically and usually happens when our CPU is idle to prevent it from effecting our execution.</p><p>We cannot force or prevent it. But we should still have an understanding of how it works so heres a few snippets of code.</p><pre>let mod = {<br>  name: &quot;Cheese&quot;<br>}</pre><p>Here we’ve made an object with the key of name and value of “Cheese” being referenced in mod. If the value of mod is overwritten then the reference is lost and sent to garbage collection.</p><pre>mod = null; // no more access to &quot;Cheese&quot; :(</pre><p>We now have no reference to the old value of “Cheese” so it is sent to garbage collection to free up space. However if there is still a reference to a data somewhere, it won’t be sent to garbage collection.</p><pre>let mod = {<br>  name: &quot;Cheese&quot;<br>}</pre><pre>let bestMod = mod; // currently holding the reference of &quot;Cheese&quot;</pre><pre>mod = null; // &quot;Cheese&quot; still exist :)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*vguMJEI2EUv6SaYDszrdMA.gif" /></figure><p>I hope I didn’t throw too much at you, so let us recap a bit.</p><pre>let cheese = &quot;We have a way to access the reference&quot;</pre><pre>if (cheese) { // &quot;We have a way to access the reference&quot;<br>  console.log(&quot;All is well :)&quot;)<br>else { // if we don&#39;t have access to the reference<br>  console.log(&quot;This is gonna be sent to garbage collection&quot;)<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*CtweRjuHjj3G2MLIDVcgxw.png" /><figcaption>Objects are retained in memory while they are reachable.</figcaption></figure><p>Did you know?</p><p>Any variable created without the let keyword is created in the global scope and is never eligible for garbage collection. Doing so can cause memory leaks which occurs when a computer program incorrectly manages memory allocations in such a way that memory which is no longer needed is not released. A memory leak may also happen when an object is stored in memory but cannot be accessed by the running code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*8dBOz8GcutaOys8w-My05A.gif" /><figcaption>Us as programmers</figcaption></figure><p>I hope you enjoyed my little snippet on garbage collection and have a better understanding of what it is!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75006fadad3b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Beginner’s Guide To CSS Grids]]></title>
            <link>https://medium.com/@kahyap13/a-beginners-guide-to-css-grids-31e418f44229?source=rss-c5ab8c5623d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/31e418f44229</guid>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Kah Yap]]></dc:creator>
            <pubDate>Tue, 22 Jan 2019 04:26:13 GMT</pubDate>
            <atom:updated>2019-01-22T05:13:06.447Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*yUuSIM2gwmjq7Lru_DdKHQ.gif" /><figcaption>CSS == Cascading Style Sheets</figcaption></figure><p>CSS Grid Layout is a two dimensional system, meaning it can handle both columns and rows</p><p>You apply grids to a container and and the direct children of that container. Each of the individual item will then become an item and gets placed on a grid</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*jlOTlGFNjhUYlyS93xIebw.gif" /></figure><p>To create a CSS Grid we need to go to our html file and make a parent wrapper which will be our grid</p><pre>&lt;div class=&quot;wrapper&quot;&gt;</pre><pre>&lt;/div&gt;</pre><p>Next we have to put items in them which will be the contents of our grid</p><pre>&lt;div class=&quot;wrapper&quot;&gt;<br>  &lt;div&gt; Just some content &lt;/div&gt;<br>  &lt;div&gt; I am an item &lt;/div&gt;<br>  &lt;div&gt; blah blah blah &lt;/div&gt;<br>&lt;/div&gt;</pre><p>In our CSS file we write</p><pre>.wrapper {<br>  display: grid;<br>}</pre><p>Now everything inside our div with the class wrapper is a grid which doesn’t do much by itself but if you write ‘grid-template-columns: 1fr, 1fr;’ into our wrapper class you can break everything in our wrapper into two equal columns! You can even use ‘grid-template-rows’ to create rows instead!</p><pre>.wrapper {<br>  display: grid;<br>  grid-template-columns: 1fr, 1fr;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Jw9rM2OTkDAUYTswfrbrDQ.gif" /><figcaption>Grids Grids Grids</figcaption></figure><p>Let us take it one step further with both rows and columns by creating a grid with three columns and two rows.</p><pre>.wrapper {<br>  display: grid;<br>  grid-template-columns: 1fr 1fr 1fr;<br>  grid-template-rows: 1fr 1fr;<br>}</pre><p>The ‘1fr’ you see means one fraction, so in our example above our ‘grid-template-columns: 1fr 1fr 1fr;’ means that we are going to have three separate columns all taking a third of the space within the grid. You can even use ‘%’ or ‘px’ and write it like this</p><pre>grid-template-columns: 100px 200px 100px;<br>grid-template-columns: 30% 40% 30%;</pre><p>Now that you have a basic understanding of how CSS Grids work, lets kick it up a notch!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*6rIFAdnNhNhWBvzkJ_mK5A.gif" /></figure><p>From the example above, lets give each one of the items their own class</p><pre>&lt;div class=&quot;wrapper&quot;&gt;<br>  &lt;div class=&quot;item1&quot;&gt; Just some content &lt;/div&gt;<br>  &lt;div class=&quot;item2&quot;&gt; I am an item &lt;/div&gt;<br>  &lt;div class=&quot;item3&quot;&gt; blah blah blah &lt;/div&gt;<br>&lt;/div&gt;</pre><p>In our CSS file, call the class name that you would like to manipulate. By writing ‘grid-column: 1/4’ into the class name, we are telling our item to span from the 1st line to the 4th line taking three squares of space which is also known as ‘Grid Tracks’</p><pre>.item1 {<br>  grid-column: 1/4;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*jqnv_mKrmEwDTH2VFj7mdw.png" /><figcaption>Grid Lines are the lines that make up the grid. These can be horizontal or vertical</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*r1kkzMS655bhFdsIUZWZ-Q.png" /><figcaption>Grid Tracks is the space between two Grid Lines, either horizontal or vertical</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*BmAJ5ONIIh2yAYRjgyTGNA.png" /></figure><p>With what we have learned here, we can make our websites mobile responsive meaning that our website will scale to the size of our browser or if it is being viewed on a phone without the need of media query</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*l6NalTsCC_3rbnyl70U7yA.gif" /></figure><p>I hope reading this blog has made CSS Grids easier to understand!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31e418f44229" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Helper Methods]]></title>
            <link>https://medium.com/@kahyap13/helper-methods-4ce8b46609c0?source=rss-c5ab8c5623d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ce8b46609c0</guid>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Kah Yap]]></dc:creator>
            <pubDate>Thu, 10 Jan 2019 00:52:47 GMT</pubDate>
            <atom:updated>2019-01-10T00:52:47.385Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello there! For those of you who like to write huge lines of code, I’m going to show you how amazing helper methods are!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*626L9e9xvQKxlcYZulBIGA.gif" /></figure><p>Helper methods is a method that helps another method to perform its task. These are typically used when a method has to perform a complicated task that is composed of several smaller tasks. The smaller tasks are often performed by helper methods</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*5lbzR6ExPKftgDSvlas6ug.gif" /><figcaption>A method that helps your methods</figcaption></figure><p>Heres an example, you want to find all prime numbers that is a factor of a certain number. Sounds intimidating at first but when we break it down to multiple steps it’ll start to make a bit more sense.</p><pre>def prime_factors(num)</pre><pre>  prime = []</pre><pre>    (1..num).each do |i|  # iterate from 1 through num</pre><pre>      if num % i == 0 &amp;&amp; is_prime?(i)</pre><pre>        prime &lt;&lt; i </pre><pre>      end</pre><pre>    end</pre><pre>  return prime  # return the array of prime numbers</pre><pre>end</pre><p>Here we have declared a prime_factors function with an empty array set to prime. We want to iterate through all the numbers leading to itself so we used an each iterator to see if it is a factor. Now we want to see if that current factor is prime.</p><p>A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers.</p><p>If you attempt to solve this problem in one huge block of code, you must be insane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*t0Jdh55xdQUTEpHH8_nxgg.gif" /></figure><p>Sounds like an opportunity to use a helper method!</p><pre>def is_prime?(n)</pre><pre>  if n &lt; 2</pre><pre>    return false</pre><pre>  end</pre><pre>  (2...n).each do |i|</pre><pre>    if n % i == 0</pre><pre>      return false   #  this will end the function if its not prime</pre><pre>    end</pre><pre>  end</pre><pre>  return true          # it is prime if it passes both if cases</pre><pre>end</pre><p>So what we did here is create another method to see if a number that is given as an argument is prime or not. Awesome! So now our if condition from above is both a factor and a prime number we can shovel it into the array. Now we can finally return that array of prime numbers!</p><p>Not only did we make our prime_factors function a lot smaller and easier to read, but also we can always find out if a number is prime from the is_prime? function making our code DRY! (Don’t repeat your code!) If you ever feel like you are constantly writing the same code, perhaps that would be a good time to use our buddy helper methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*Vx4VBEigArV8dFkkeVa-HA.gif" /><figcaption>Helper Methods == Less Code</figcaption></figure><p>Awesome! You are now one step closer to becoming a great developer!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*EZHatNxLVkHCsN5cJpK7OA.gif" /><figcaption>See ya later :)</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ce8b46609c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>