<?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[Sunki Baek - Medium]]></title>
        <description><![CDATA[JavaScript, TypeScript, React, React Native - Medium]]></description>
        <link>https://medium.com/sunki-baek?source=rss----a7c7e30eb13a---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Sunki Baek - Medium</title>
            <link>https://medium.com/sunki-baek?source=rss----a7c7e30eb13a---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 03:07:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/sunki-baek" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Data Structures and Algorithm Review 1/2]]></title>
            <link>https://medium.com/sunki-baek/data-structures-and-algorithm-review-1-2-86664f38d783?source=rss----a7c7e30eb13a---4</link>
            <guid isPermaLink="false">https://medium.com/p/86664f38d783</guid>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Sunki Baek]]></dc:creator>
            <pubDate>Mon, 23 May 2022 00:52:05 GMT</pubDate>
            <atom:updated>2022-05-21T23:26:05.922Z</atom:updated>
            <content:encoded><![CDATA[<p>Array, LinkedList, Stack, Queue, and Tree</p><h3>Array</h3><p>The Array is a data structure where you can store data in a linear fashion. Array occupies contiguous spaces in memory. By doing so, we can access elements using indexes.</p><p>If you already know the index of the value, a read operation on Array will have O(1) time complexity. If you are searching for a value without knowing the index, you have to go from the beginning to the end in the worst case. That makes searching value to be an O(n) operation.</p><p>Adding a value to the back of an array is an O(1) operation if you know the index of the last element in the array. However, adding a value to the front of an array takes O(n), since after adding the value, all the consecutive values need to be shifted one index to the right.</p><p>Since Array is static, if it reaches its capacity while adding values to it, you need to increase its space. Developers seem to choose to use 2x of the original capacity when they need to do this. The process is making a new Array with 2x capacity and then filling it with the values from the original Array. This process takes O(n) time since it iterates through all the elements in the Array but adding an element to an Array is still amortized to be O(1) considering the ultimate number of elements can be really big.</p><h3>Linked List</h3><p>Linked List is also a linear data structure where you can make a node point to another. Unlike an Array, having nodes connected to another means it does not have to occupy adjacent memory cells. It also means you do not have indexes to point nodes, you need a reference to the root node and use it to iterate the entire list.</p><p>Adding a value to the head of a Linked List is O(1) operation since it is a task of switching references from an old node to a new one. Adding to the back of a LinkedList takes O(n) since you have to iterate all the way down to the back to access the node. Removing a node or searching for value goes through the same operation.</p><p>A circular Linked List is a list where the end node is connected to the root node. Useful when you need to cycle through the list continuously.</p><p>A doubly-linked Linked List is a list where each node has a reference to the previous node as well as the one after it. Having access to the previous node can make implementing the removing operations simpler.</p><h3>Stack</h3><p>Stack is a linear data structure following the Last-In-First-Out principle. As in <em>a stack of plates</em>, you can pop the top element of the stack or push a new element on top of it. Both pop and push operation happens at the same end and takes O(1) time. You can use either Array or Linked List to implement Stack.</p><h3>Queue</h3><p>Queue is similar to Stack but follows the First-In-First-Out principle. As in <em>a line in front of a cashier</em>, you can enqueue or add an element to the back and dequeue or remove an element from the front. Unlike Stack, these operations happen on the other side of the ends and takes O(1) time. You can use either Array or Linked List to implement Queue.</p><h3>Tree</h3><p>Tree is a hierarchical data structure that shapes like upside-down tree. A node can have multiple children and a child node can have their child nodes. Nodes are connected from top to bottom but not between siblings. Root node means the central node where the structure begins. Leaf nodes are the ones at the bottom most in the structure without their children.</p><p>Because of recurring nature of Tree, you can usually use recursion to traverse nodes in the Tree.</p><p>A node means each data point edges mean the connection among nodes.</p><p>The depth of a node is the number of edges from the node to the root node. A root node has zero depth as you would measure the depth of water from the surface.</p><p>The height of a node is the number of edges on the longest paths from the node to a leaf. A leaf node has zero height.</p><p>The height of a tree equals to the height of its root node or the depth of its deepest node.</p><blockquote><a href="https://stackoverflow.com/a/2603707">https://stackoverflow.com/a/2603707</a></blockquote><p>While a general Tree has no constraints on how child nodes can be added, Binary Tree can only have up to two children. A full binary tree is a tree where every node has either zero or two children. A complete binary tree is a tree filled at every level except for the last level and all nodes on the last level are pushed as far left as much as possible. A perfect binary tree is a tree with all interior nodes with two children and leaves have the same depth (as in an ancestry chart).</p><blockquote><a href="https://en.wikipedia.org/wiki/Binary_tree">https://en.wikipedia.org/wiki/Binary_tree</a></blockquote><p>Binary Search Tree is a Binary Tree with smaller child on the left and bigger child on the right, and can be used various searching purposes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86664f38d783" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sunki-baek/data-structures-and-algorithm-review-1-2-86664f38d783">Data Structures and Algorithm Review 1/2</a> was originally published in <a href="https://medium.com/sunki-baek">Sunki Baek</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basics of JavaScript for technical interviews]]></title>
            <link>https://medium.com/sunki-baek/basics-of-javascript-for-technical-interviews-7d3f7d1a15c2?source=rss----a7c7e30eb13a---4</link>
            <guid isPermaLink="false">https://medium.com/p/7d3f7d1a15c2</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sunki Baek]]></dc:creator>
            <pubDate>Sat, 14 May 2022 19:10:48 GMT</pubDate>
            <atom:updated>2022-05-14T19:10:48.769Z</atom:updated>
            <content:encoded><![CDATA[<p>Do you remember how to read from files?</p><p>Even if you use JavaScript on a daily basis, you might have forgotten some of the very basics of JavaScript that are required for some technical interviews. Let’s refresh our minds on these:</p><ul><li>How to read from the console</li><li>How to process command line arguments</li><li>How to read and write from and to files</li><li>How to parse CSV or text files</li><li>How to read the length of string</li><li>How to declare and use 2D arrays</li></ul><h3>How to read from the console</h3><p>To read from the console using JavaScript, you can use readline module from Node.js.</p><pre>import readline from &quot;readline&quot;;</pre><pre>const rl = readline.createInterface({<br>  input: process.stdin,<br>  output: process.stdout,<br>});</pre><pre>rl.question(&quot;Input data: &quot;, (data) =&gt; {<br>  console.log(`Data: ${data}`);</pre><pre>  rl.close();<br>});</pre><p>And the result is like this:</p><pre>Input data: apple,watermelon,lemon<br>Data: apple,watermelon,lemon</pre><p>You can read more about it in <a href="https://nodejs.org/api/readline.html">the Node.js doc</a>.</p><h3>How to process command line arguments</h3><p>In the Node.js environment, command line arguments are stored in process.argv. So you can simply output the arguments like:</p><pre>console.log(`Arguments: ${process.argv}`);</pre><p>process.argv is an array of strings and the first two elements contain the interpreter and the file path. So just to extract arguments you can use:</p><pre>const argvs = process.argv.slice(2);</pre><pre>for (const argv of argvs) {<br>  console.log(`Argument: ${argv}`);<br>}</pre><p>In recent versions of the Node.js, you can also import process using import or require:</p><pre>import process from &#39;node:process&#39;;<br>const process = require(&#39;node:process&#39;);</pre><p>And the output is:</p><pre>yarn run-script src/02-process-command-line-argv.ts option1=apple option2=orange</pre><pre>Argument: option1=apple<br>Argument: option2=orange</pre><p>You can read more about it in <a href="https://nodejs.org/api/process.html#processargv">the doc</a>.</p><h3>How to read and write from and to files</h3><p>To process files, you can use the fs module. Reading from a file and making a copy can be like this:</p><pre>import fs from &quot;node:fs/promises&quot;;</pre><pre>const main = async () =&gt; {<br>  const sampleFile = await fs.readFile(&quot;sample.csv&quot;, &quot;utf-8&quot;);</pre><pre>  console.log(sampleFile);</pre><pre>  await fs.writeFile(&quot;sample-copy.csv&quot;, sampleFile);<br>};</pre><pre>main();</pre><p>In the output, you can see the content of the sample.csv. You can also see sample-copy.csv is created.</p><p>These APIs have three versions: a promise version, a callback version, and a synchronous version. You can choose whatever is best for your situation.</p><p>To read more about fs, visit <a href="https://nodejs.org/api/fs.html">the doc</a> here.</p><h3>How to parse CSV or text files</h3><p>To parse CSV or text files, first, you can split each line with the new line character (\n). After that, you can split each line with a comma.</p><pre>const CSV = `apple,orange,banana<br>pear,grape,pineapple<br>milk,cheese,yogurt<br>`;</pre><pre>const main = async () =&gt; {<br>  const lines = CSV.trim().split(&quot;\n&quot;);</pre><pre>  for (const line of lines) {<br>    const elements = line.split(&quot;,&quot;);</pre><pre>    console.log(elements);<br>  }<br>};</pre><pre>main();</pre><p>And the output is:</p><pre>[ &#39;apple&#39;, &#39;orange&#39;, &#39;banana&#39; ]<br>[ &#39;pear&#39;, &#39;grape&#39;, &#39;pineapple&#39; ]<br>[ &#39;milk&#39;, &#39;cheese&#39;, &#39;yogurt&#39; ]</pre><p>It is straight forward and you just need to keep in mind two things:</p><ul><li>Remove unwanted spaces between elements or new line characters at the end of the file.</li><li>If the element is not a string type, you need to convert them into the type you want. For example, you can convert the element into a number using Number(element).</li></ul><h3>How to split strings</h3><h3>How to read the length of string</h3><h3>How to declare and use 2D arrays</h3><p>Happy coding 😎</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d3f7d1a15c2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sunki-baek/basics-of-javascript-for-technical-interviews-7d3f7d1a15c2">Basics of JavaScript for technical interviews</a> was originally published in <a href="https://medium.com/sunki-baek">Sunki Baek</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>