<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nathan Kurz</title>
    <description>The latest articles on DEV Community by Nathan Kurz (@nathankurz91).</description>
    <link>https://dev.to/nathankurz91</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F375859%2Fdc3ac9b2-eee7-4afc-8099-d7d41bc5bb4d.png</url>
      <title>DEV Community: Nathan Kurz</title>
      <link>https://dev.to/nathankurz91</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nathankurz91"/>
    <language>en</language>
    <item>
      <title>Find the Length of the Last Word in a String - javascript</title>
      <dc:creator>Nathan Kurz</dc:creator>
      <pubDate>Wed, 31 May 2023 20:06:52 +0000</pubDate>
      <link>https://dev.to/nathankurz91/find-the-length-of-the-last-word-in-a-string-javascript-41dg</link>
      <guid>https://dev.to/nathankurz91/find-the-length-of-the-last-word-in-a-string-javascript-41dg</guid>
      <description>&lt;p&gt;Let's solve a coding challenge. We will discuss how to find the length of the last word in a string using javascript as our programming language. &lt;/p&gt;

&lt;p&gt;First the problem statement: &lt;br&gt;
&lt;strong&gt;Given a string, return the length of the last word in the string.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To understand how to solve the problem, let's start with an example. Let's say this is our string:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const str = 'hello i am a string'&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;We need to isolate the last word in the string, find its length, and return it. Let's start by isolating the last word. We can separate all of the words in this string and store them in an array. In javascript we use split for this. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;const words = str.split(' ');&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We pass a space into the function as the delimiter. This will separate the words into the array by the spaces. Once we have our array, we need to target the last element of the array and get it's length.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const lastWordLength = words[words.length - 1].length;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We can then return this value and our function is complete. There are two edge cases we inspect. What if there are extra spaces in our string? &lt;/p&gt;

&lt;p&gt;&lt;code&gt;str = '   hello i am   a string    '&lt;/code&gt;;&lt;/p&gt;

&lt;p&gt;To account for this edge case, we need to trim the extra space from the string before we split it. The code would change to this.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const words = str.trim().split(' ');&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The other edge case is if the string is an empty string. In this case, we would just return 0;&lt;/p&gt;

&lt;p&gt;Now we have accounted for our edge cases and the problem is effectively solved. This is what the completed function could look like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function lengthOfLastWord(s) {
    if (s.length === 0) {
        return 0;
    } else {
        const words = s.trim().split(' ');
        const lengthOfLastWord = words[words.length - 1].length;
        return lengthOfLastWord;
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! Have a wonderful day!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Longest Palindromic Substring: JavaScript</title>
      <dc:creator>Nathan Kurz</dc:creator>
      <pubDate>Wed, 13 Apr 2022 16:37:38 +0000</pubDate>
      <link>https://dev.to/nathankurz91/longest-palindromic-substring-javascript-5aj4</link>
      <guid>https://dev.to/nathankurz91/longest-palindromic-substring-javascript-5aj4</guid>
      <description>&lt;p&gt;A palindrome is any set of characters that read the same forwards and backwards. For example: 'noon' is a palindrome, and 'loon' is not. Both of these strings contain palindromic substrings 'oo'.&lt;/p&gt;

&lt;h2&gt;
  
  
  Objective
&lt;/h2&gt;

&lt;p&gt;Find the longest set of characters in a string that is a palindrome, or the 'longest palindromic substring'.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solutions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Solution 1
&lt;/h3&gt;

&lt;p&gt;There are a few different ways to solve this, but I am going to stick to the two that I used personally. My initial thoughts were to get every possible substring and check if they were palindromes. If the string is a palindrome, check the length. If the length is greater than the length of the current longest, set the current longest equal to the current string. &lt;/p&gt;

&lt;p&gt;This solution is straightforward and definitely works, however there is a glaring issue. It's very slow for large strings. You have a nested loop to get every possible substring which has a O(n^2) runtime, and you have to check each substring to see if it is a palindrome which is O(n) giving you a total runtime of O(n^3). I tested this solution using node on my terminal and it worked fine, but when I went to submit the solution it failed because it exceeded the time limit. Just in case you are curious I will show a copy of this solution below, but we will be looking at a much faster option next.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * @param {string} s
 * @return {string}
 */&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;longestPalindrome&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// check base case&lt;/span&gt;
    &lt;span class="c1"&gt;// examine every possible substring&lt;/span&gt;
    &lt;span class="c1"&gt;// if substring and length is longer than current longest, set to longest&lt;/span&gt;
    &lt;span class="c1"&gt;// return longest&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isPalindrome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;ss&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;substring&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isPalindrome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ss&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ss&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ss&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;isPalindrome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;reverse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Solution 2
&lt;/h3&gt;

&lt;p&gt;I had to research a few different ways of solving this problem. I chose to research an algorithm that appeared to be the least convoluted. I wrote out some pseudocode and went through a few iterations by hand to better understand the algorithm.&lt;/p&gt;

&lt;p&gt;There is no need to check every possible substring. Instead, we can iterate through the string once. At each index, we check to see if the positions to the left and right of the current index are equal. If they are equal, then the substring is a palindrome. We continue incrementing and decrementing the left and right pointers until the substring is no longer a palindrome. If the substring is not a palindrome, we exit the inner loop and continue to the next index in the string (outer loop).&lt;/p&gt;

&lt;p&gt;Below is a snippet of the code used in this solution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;longestPalindrome&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;longest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// loop through string once&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// use two different starting positions to&lt;/span&gt;
        &lt;span class="c1"&gt;// account for even or odd strings&lt;/span&gt;
        &lt;span class="nx"&gt;checkLeftAndRight&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;checkLeftAndRight&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;checkLeftAndRight&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// subtract left from right and add one to get current&lt;/span&gt;
            &lt;span class="c1"&gt;// length of substring&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;longest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// set longest to current substring&lt;/span&gt;
                &lt;span class="nx"&gt;longest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;longest&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This was an interesting problem. My goal in practicing and analyzing these solutions is to one day have a big enough toolkit that I can think of multiple solutions for many of the problems I come across without having to research them. Hope this helps someone out there :)&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>programming</category>
      <category>leetcode</category>
    </item>
    <item>
      <title>LeetCode 26: Remove Duplicates from Sorted Array</title>
      <dc:creator>Nathan Kurz</dc:creator>
      <pubDate>Fri, 08 Apr 2022 05:27:51 +0000</pubDate>
      <link>https://dev.to/nathankurz91/leetcode-26-remove-duplicates-from-sorted-array-2o5e</link>
      <guid>https://dev.to/nathankurz91/leetcode-26-remove-duplicates-from-sorted-array-2o5e</guid>
      <description>&lt;p&gt;Let's talk about removing duplicates. Normally, removing duplicates from a sorted array would be quick work. You just add each value to a set. Since all values in sets must be unique you simply return the values contained in the set. This was not a valid solution for this problem.&lt;/p&gt;

&lt;p&gt;The problem states that you have to modify the array in place. That means I can't create another data structure to store my values when I find any duplicates. Admittedly, the solution is still straightforward. I have not had the pleasure of using the splice() function in JavaScript too many times, so it took me a bit longer than I would have liked until I rediscovered it.&lt;/p&gt;

&lt;p&gt;Now we will build the solution. I'll explain it first with some pseudocode, and then present the actual code below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Loop through the array&lt;/li&gt;
&lt;li&gt;The array size will change when we remove an element, so we need to use a variable to store the initial array length&lt;/li&gt;
&lt;li&gt;check if i is greater than or equal to array.length&lt;/li&gt;
&lt;li&gt;break if true&lt;/li&gt;
&lt;li&gt;check if i equals i+1&lt;/li&gt;
&lt;li&gt;if true, remove element at index i with splice()&lt;/li&gt;
&lt;li&gt;decrement i to recheck that same position in case of further duplicates&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Like I said, pretty straightforward. I tend to overthink these algorithm problems. That's why I'm practicing!&lt;/p&gt;

&lt;p&gt;Solution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;removeDuplicates&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;numsLength&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;numsLength&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hope you learned something!! Have a great day and remember to GO OUTSIDE :)&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>programming</category>
      <category>node</category>
    </item>
    <item>
      <title>LeetCode 1313. Decompress Run-Length Encoded List - Javascript Algorithm Practice</title>
      <dc:creator>Nathan Kurz</dc:creator>
      <pubDate>Fri, 24 Jul 2020 15:54:48 +0000</pubDate>
      <link>https://dev.to/nathankurz91/leetcode-1313-decompress-run-length-encoded-list-javascript-algorithm-practice-1e9o</link>
      <guid>https://dev.to/nathankurz91/leetcode-1313-decompress-run-length-encoded-list-javascript-algorithm-practice-1e9o</guid>
      <description>&lt;p&gt;Hello everyone! &lt;/p&gt;

&lt;p&gt;Practicing LeetCode is one of my favorite ways to keep my mind and coding skills sharp. I don't think I would have been able to pass my interview questions without the help of LeetCode. I believe they provide a great service for developers everywhere. Without further ado, let's solve this thing! &lt;/p&gt;

&lt;h2&gt;
  
  
  The official problem statement:
&lt;/h2&gt;

&lt;p&gt;We are given a list nums of integers representing a list compressed with run-length encoding.&lt;/p&gt;

&lt;p&gt;Consider each adjacent pair of elements&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;[freq, val] = [nums[2*i], nums[2*i+1]]&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 with&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;i &amp;gt;= 0&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
  For each such pair, there are freq elements with value val concatenated in a sublist. Concatenate all the sublists from left to right to generate the decompressed list.&lt;/p&gt;

&lt;p&gt;Return the decompressed list.&lt;/p&gt;
&lt;h2&gt;
  
  
  Analysis
&lt;/h2&gt;

&lt;p&gt;At first, this sounded a bit confusing to me, but it's basically just saying each pair of elements in the array represents a frequency and a value that needs to be stored in the new array. So if we were given an array&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;nums = [1, 2, 4, 6]&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 then our first pair would be (1, 2) and our second pair would be (4, 6). So from our first pair, we would store the value 2, one time. We would store the value 4, six times from the second pair. &lt;/p&gt;
&lt;h2&gt;
  
  
  The solution
&lt;/h2&gt;

&lt;p&gt;The way I went about solving this was straightforward. We need to go through the list one pair at a time, get the values for each pair, and append the appropriate values the correct amount of times. We will go through it step by step!&lt;/p&gt;
&lt;h3&gt;
  
  
  Iterate over the list
&lt;/h3&gt;

&lt;p&gt;We need to iterate over the given list of numbers one pair at a time. To do this, we can use a for loop that increments by two every iteration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * @param {number[]} nums
 * @return {number[]}
 */&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;decompressRLElist&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Grab 'freq' and 'val' from the corresponding indices.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * @param {number[]} nums
 * @return {number[]}
 */&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;decompressRLElist&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;freq&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Store 'val' in a new array 'freq' amount of times
&lt;/h3&gt;

&lt;p&gt;I approached this portion by adding another loop (nested) to add the value the appropriate amount of times!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * @param {number[]} nums
 * @return {number[]}
 */&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;decompressRLElist&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// create new array (decompressed list)&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dcomList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;freq&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;freq&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;dcomList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;freq&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Return the new decompressed list
&lt;/h3&gt;

&lt;p&gt;The last thing to do is to return dcomList!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * @param {number[]} nums
 * @return {number[]}
 */&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;decompressRLElist&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// create new array (decompressed list)&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dcomList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;freq&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;freq&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;dcomList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;freq&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;dcomList&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Thoughts
&lt;/h2&gt;

&lt;p&gt;My solution is a basic one, but it definitely gets the job done. I always like to solve these problems the simplest way I can, and then I go and look at the discussion page to see all the different ways other people go about solving them. This is probably what helps me grow most as a problem solver. It allows me to work through problems on my own, and then I can expand that knowledge through the work of others!&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus solution
&lt;/h2&gt;

&lt;p&gt;Here is a solution written by LeetCode user &lt;em&gt;ahmedengu&lt;/em&gt; that drastically reduces the number of lines of code (to just one)!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * @param {number[]} nums
 * @return {number[]}
 */&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;decompressRLElist&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;times&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;constant&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])))&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I see this type of solution to these problems on LeetCode all the time. I want to keep practicing and memorize the builtin javascript methods so that I can better utilize them to come up with unique solutions like this!&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Transitioning from C++ Windows App Development to Modern JavaScript Based Web Development</title>
      <dc:creator>Nathan Kurz</dc:creator>
      <pubDate>Thu, 14 May 2020 04:49:45 +0000</pubDate>
      <link>https://dev.to/nathankurz91/transitioning-from-c-windows-app-development-to-modern-javascript-based-web-development-2ach</link>
      <guid>https://dev.to/nathankurz91/transitioning-from-c-windows-app-development-to-modern-javascript-based-web-development-2ach</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FT6bucC8.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FT6bucC8.jpg" alt="C++ and JavaScript"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A Little History
&lt;/h2&gt;

&lt;p&gt;I'm writing about my current experience in the software development industry. I graduated from a four-year university in May of 2019. There I studied Computer Science with the hopes of landing a job in the field. Through luck and perseverance, I was able to obtain a wonderful position with an insurance company as part of the software division.&lt;/p&gt;

&lt;p&gt;This opportunity was amazing. I was met with a brilliant team to mentor me. They offered a SAAS (Software as a Service) product, so they had a fairly large IT program. My managers were extremely helpful and would work with me whenever they could to help me with issues. The same can be said of my teammates. The software I worked on was written in C++ using the MFC framework for the GUI components. &lt;/p&gt;

&lt;h2&gt;
  
  
  C++ Development
&lt;/h2&gt;

&lt;p&gt;I wrote C++ programs for eleven months. This allowed me to better understand memory management, passing by reference, and other concepts specific to C++. Before this experience, I had only used C++ for one semester in my Data Structures class. I basically went from being aware of these concepts to understanding them and using them on a regular basis. &lt;/p&gt;

&lt;p&gt;I also learned some important software engineering principles from my colleagues. I was constantly being mentored on things like code structure, best practices, and different ways of solving new problems. The learning experience was incredible.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Job Offer
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1499202977705-65f436dac18a%3Fixlib%3Drb-1.2.1%26ixid%3DeyJhcHBfaWQiOjEyMDd9%26auto%3Dformat%26fit%3Dcrop%26w%3D1051%26q%3D80" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1499202977705-65f436dac18a%3Fixlib%3Drb-1.2.1%26ixid%3DeyJhcHBfaWQiOjEyMDd9%26auto%3Dformat%26fit%3Dcrop%26w%3D1051%26q%3D80" alt="Jumping Man"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Several months later, my friend from college told me there were openings at his much larger company. I didn't really think I had much chance of getting the job, but I did well in the interviews and got an offer. I was offered a significant amount more at the new company, and I thought the opportunity might benefit me more in the future. &lt;/p&gt;

&lt;p&gt;I began working for my new company this year in January. My new team is completely different than my team at my last company. I'm not saying they are worse or better, but it's a completely different environment. My team consists of three individuals; myself and two others who are both younger than me. This hasn't proved to be an issue though, as I believe they are both brilliant individuals who consistently amaze me with their problem-solving skills. I feel grateful to have two people on my team like them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Transition to Web Dev
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1545986467-13cfe33c156e%3Fixlib%3Drb-1.2.1%26ixid%3DeyJhcHBfaWQiOjEyMDd9%26auto%3Dformat%26fit%3Dcrop%26w%3D968%26q%3D80" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1545986467-13cfe33c156e%3Fixlib%3Drb-1.2.1%26ixid%3DeyJhcHBfaWQiOjEyMDd9%26auto%3Dformat%26fit%3Dcrop%26w%3D968%26q%3D80" alt="Transitioning sand"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another large change is the technology I use to write software. I'm writing web applications in javascript. I had only written a few basic websites before this as most of my education was in Java and C++ writing more traditional server or local applications. Learning web development is proving to have a pretty steep learning curve, but I'm learning and providing value every day.&lt;/p&gt;

&lt;h3&gt;
  
  
  No Types
&lt;/h3&gt;

&lt;p&gt;One of the biggest obstacles was not using types in JavaScript. Writing in C++ had me constantly aware of the types of variables I was working with. It definitely led to confusion when trying to visually parse code in JS. Some of our projects are written in TypeScript, which felt much more familiar to me to look at. &lt;/p&gt;

&lt;h3&gt;
  
  
  Function Syntax
&lt;/h3&gt;

&lt;p&gt;Another major difference I've noticed is the syntax in regards to a function declaration. The ultimate purpose of their creation remains the same, but the syntax is completely different. I had only heard of ES6 and didn't really understand it. The short function declarations looked extremely foreign when I first started seeing them. I rather like using it now though. The short versions are so much easier to write after getting used to them.&lt;/p&gt;

&lt;p&gt;The fact that we are constantly passing functions in as parameters was another thing I struggled to completely understand. This coupled with the strange look of the new shortened function declarations caused me to miss the rigid structure I was used to in C++. &lt;/p&gt;

&lt;h3&gt;
  
  
  Engineering Principles
&lt;/h3&gt;

&lt;p&gt;After eleven months of writing C++, I was developing a much better system of engineering my applications and managing my code. This was one thing that didn't suffer as much during the transition. After learning the basics of JavaScript, I find that I am able to implement a lot of the software engineering concepts I learned from my first company.&lt;/p&gt;

&lt;h3&gt;
  
  
  Visual Studio to Visual Studio Code
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.talkingdotnet.com%2Fwp-content%2Fuploads%2F2015%2F12%2FVisual-Studio-Code.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.talkingdotnet.com%2Fwp-content%2Fuploads%2F2015%2F12%2FVisual-Studio-Code.png" alt="Comparing Logos"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I wrote every bit of my code at my last company in the robust Visual Studio IDE. Every developer at the company used it, and it was the standard there for working with our software. This caused me to really get used to things like it's debugging and IntelliSense. As a web developer, I can pretty much use whatever IDE or text editor I want. My current team all use Visual Studio Code, so I'm sticking with that for now. Many aspects of these two pieces of software are similar, so the switch has not been so bad. I find that debugging the node applications though is not as intuitive or seamless as the experience was in Visual Studio.&lt;/p&gt;

&lt;h3&gt;
  
  
  Team Differences
&lt;/h3&gt;

&lt;p&gt;This next challenge isn't as much with the technology as it is with my team. My first team was bigger, and it had much more seasoned developers with many years of experience working on the systems at that company. The developers I work with now, though extremely intelligent, are much less experienced. This definitely does cause different issues that I am not as used to working through.&lt;/p&gt;

&lt;p&gt;My manager at company number one had about a decade of experience himself at that company. He also had a Masters in Computer Science from Georgia Tech. I don't mean to brag for him or put him on a pedestal. I only want to emphasize that when I got stuck on a problem that was proving very difficult for me to solve, he could usually help me with the issue extremely effectively. He understood the software stack so well that he knew sometimes what problems were and where they were in the code just by me describing the issues to him. His problem-solving skills were highly impressive to me.&lt;/p&gt;

&lt;p&gt;My team now has much less experience than my other co-workers, and this leads to certain issues that I didn't have to face at my last company. I realized that my first manager was shielding me from the business side of the company. I very rarely had to sit in on meetings with clients discussing requirements for features, bug fixes, and things like that. He and other leaders would build the requirements. This is not the case with my new team. We all do very well in requirements translation and providing solutions, but when we all three run into issues we don't have a seasoned veteran that we can quickly turn to for assistance. There are benefits to this though. We have had to work through issues together as a team, so we all are learning from the problem-solving process. We haven't come across an issue that we haven't been able to solve yet, so I am extremely satisfied with our performance. Sometimes we have to reach out for assistance to other areas of the company, but we are really working to get the job done.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1543386650-2be9a18d2750%3Fixlib%3Drb-1.2.1%26ixid%3DeyJhcHBfaWQiOjEyMDd9%26auto%3Dformat%26fit%3Dcrop%26w%3D1051%26q%3D80" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1543386650-2be9a18d2750%3Fixlib%3Drb-1.2.1%26ixid%3DeyJhcHBfaWQiOjEyMDd9%26auto%3Dformat%26fit%3Dcrop%26w%3D1051%26q%3D80" alt="Woman Pondering"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I don't mean to ramble, but the experience has been pretty insane and I could write about it all day. I am building a deeper appreciation for my work as I continue to learn new things every single day. I view both positions I have worked so far as extremely valuable. I wouldn't trade either of them for anything. As I continue to work and grow my knowledge and skills, I want to sometimes stop and remember just how much I have learned over the years. Sometimes I feel that the absolutely absurd amount of technical knowledge one could learn over the years puts me in this mental space where I feel like I just started. Then I tell myself that everybody else realizes this fact as well, and we are all just learning what we can and trying our best to provide reliable solutions for our companies. &lt;/p&gt;

&lt;p&gt;I plan on being in this field for a while, and I feel extremely fortunate for the opportunities that I have been given. I love programming, and I'll probably be doing some form of it for the rest of my life. And I'm pretty happy with that for now.&lt;/p&gt;

&lt;p&gt;P.S.&lt;/p&gt;

&lt;p&gt;If you read this whole article I sincerely thank you for sticking with me.&lt;/p&gt;

&lt;h3&gt;
  
  
  References for images:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://morioh.com/p/3be45e2372a2" rel="noopener noreferrer"&gt;https://morioh.com/p/3be45e2372a2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://images.unsplash.com/photo-1499202977705-65f436dac18a?ixlib=rb-1.2.1&amp;amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;amp;auto=format&amp;amp;fit=crop&amp;amp;w=1051&amp;amp;q=80" rel="noopener noreferrer"&gt;https://images.unsplash.com/photo-1499202977705-65f436dac18a?ixlib=rb-1.2.1&amp;amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;amp;auto=format&amp;amp;fit=crop&amp;amp;w=1051&amp;amp;q=80&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://images.unsplash.com/photo-1545986467-13cfe33c156e?ixlib=rb-1.2.1&amp;amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;amp;auto=format&amp;amp;fit=crop&amp;amp;w=968&amp;amp;q=80" rel="noopener noreferrer"&gt;https://images.unsplash.com/photo-1545986467-13cfe33c156e?ixlib=rb-1.2.1&amp;amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;amp;auto=format&amp;amp;fit=crop&amp;amp;w=968&amp;amp;q=80&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.talkingdotnet.com/wp-content/uploads/2015/12/Visual-Studio-Code.png" rel="noopener noreferrer"&gt;https://www.talkingdotnet.com/wp-content/uploads/2015/12/Visual-Studio-Code.png&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://images.unsplash.com/photo-1543386650-2be9a18d2750?ixlib=rb-1.2.1&amp;amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;amp;auto=format&amp;amp;fit=crop&amp;amp;w=1051&amp;amp;q=80" rel="noopener noreferrer"&gt;https://images.unsplash.com/photo-1543386650-2be9a18d2750?ixlib=rb-1.2.1&amp;amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;amp;auto=format&amp;amp;fit=crop&amp;amp;w=1051&amp;amp;q=80&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>cpp</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
