<?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: Nat's Tech Notes</title>
    <description>The latest articles on DEV Community by Nat's Tech Notes (@nats_tech_notes).</description>
    <link>https://dev.to/nats_tech_notes</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%2F804868%2Fd64746c0-1b54-4340-9676-d179ce904a0c.jpg</url>
      <title>DEV Community: Nat's Tech Notes</title>
      <link>https://dev.to/nats_tech_notes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nats_tech_notes"/>
    <language>en</language>
    <item>
      <title>Day 5/30 Days of CodeWars: JavaScript Edition</title>
      <dc:creator>Nat's Tech Notes</dc:creator>
      <pubDate>Tue, 05 Jul 2022 01:14:35 +0000</pubDate>
      <link>https://dev.to/nats_tech_notes/day-530-days-of-codewars-javascript-edition-41mn</link>
      <guid>https://dev.to/nats_tech_notes/day-530-days-of-codewars-javascript-edition-41mn</guid>
      <description>&lt;p&gt;I'm back with more CodeWars katas! I took a break to focus on other things for a while, but now my mind is refreshed and ready to solve some more coding challenges.&lt;/p&gt;




&lt;p&gt;CodeWars challenges solved&lt;br&gt;
1) &lt;a href="https://www.codewars.com/kata/558fc85d8fd1938afb000014/train/javascript"&gt;Sum of two lowest positive integers (7 kyu)&lt;/a&gt;&lt;br&gt;
2) &lt;a href="https://www.codewars.com/kata/578553c3a1b8d5c40300037c/train/javascript"&gt;Ones and Zeros (7 kyu)&lt;/a&gt;&lt;br&gt;
3) &lt;a href="https://www.codewars.com/kata/57cebe1dc6fdc20c57000ac9/train/javascript"&gt;Shortest Word (7 kyu)&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Kata 1: Sum of two lowest positive integers
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Instructions
&lt;/h3&gt;

&lt;p&gt;Create a function that returns the sum of the two lowest positive numbers given an array of minimum 4 positive integers. No floats or non-positive integers will be passed.&lt;/p&gt;

&lt;p&gt;For example, when an array is passed like &lt;code&gt;[19, 5, 42, 2, 77]&lt;/code&gt;, the output should be &lt;code&gt;7&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;[10, 343445353, 3453445, 3453545353453]&lt;/code&gt; should return &lt;code&gt;3453455&lt;/code&gt;.&lt;/p&gt;


&lt;h3&gt;
  
  
  Breaking down the problem with P.R.E.P.
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Parameters&lt;/u&gt;&lt;br&gt;
The function expects one parameter: an array of 4 or more &lt;br&gt;
positive integers.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Returns&lt;/u&gt;&lt;br&gt;
The function should return one value: the sum of the 2 lowest numbers in the array.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;br&gt;
The following test cases are provided by CodeWars.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[5, 8, 12, 19, 22], 13
[15, 28, 4, 2, 43], 6
[3, 87, 45, 12, 7], 1
[23, 71, 33, 82, 1], 24
[52, 76, 14, 12, 4], 16
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;The array is the parameter passed to the function and the number is the integer that should be returned from the function.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;em&gt;See pseudo code section for each solution&lt;/em&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Solution 1: Sorting the array
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Create a new array with sorted numbers from smallest to largest.
2) Return the sum of the first two numbers in the array.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;sumTwoSmallestNumbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sortedNums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&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;sortedNums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;sortedNums&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Notes&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort"&gt;&lt;code&gt;.sort()&lt;/code&gt; array method&lt;/a&gt; - as the name suggests - sorts the elements of the array and returns the sorted array. It can receive an optional comparison function - like in the solution above - to sort the array in a specific manner. In this solution, passing it the comparison function of &lt;code&gt;a - b&lt;/code&gt; will sort the numbers from lowest value to highest value.&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 2: Using array destructuring
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;This solution is similar to the one above but uses a different method of selecting the numbers inside the array called &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment"&gt;array destructuring&lt;/a&gt;. When working with arrays, it can be a very useful method to work with the elements inside the array.&lt;/em&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;sumTwoSmallestNumbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&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;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&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;&lt;strong&gt;&lt;em&gt;Notes&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of declaring a variable storing the complete sorted array, a new array is declared holding only two values: &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;, which will automatically hold the values of the first two numbers in the sorted array.&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 3: One-liner
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;The following solution combines the two lines of code from solution 1 into a single line of code.&lt;/em&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;sumTwoSmallestNumbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numbers&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;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;numbers&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Notes&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;.sort()&lt;/code&gt; array method does not actually make a copy of the array but mutates the original array. So instead of storing the sorted array in a new variable like in solution 1, the elements can be selected directly from the array passed to the argument once it has been sorted.&lt;/p&gt;




&lt;h2&gt;
  
  
  Kata 2: Ones and Zeros
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Instructions
&lt;/h3&gt;

&lt;p&gt;Given an array of ones and zeroes, convert the equivalent binary value to an integer.&lt;/p&gt;

&lt;p&gt;Eg: &lt;code&gt;[0, 0, 0, 1]&lt;/code&gt; is treated as &lt;code&gt;0001&lt;/code&gt; which is the binary representation of &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Testing: [0, 0, 0, 1] ==&amp;gt; 1
Testing: [0, 0, 1, 0] ==&amp;gt; 2
Testing: [0, 1, 0, 1] ==&amp;gt; 5
Testing: [1, 0, 0, 1] ==&amp;gt; 9
Testing: [0, 0, 1, 0] ==&amp;gt; 2
Testing: [0, 1, 1, 0] ==&amp;gt; 6
Testing: [1, 1, 1, 1] ==&amp;gt; 15
Testing: [1, 0, 1, 1] ==&amp;gt; 11
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, the arrays can have varying lengths, not just limited to &lt;code&gt;4&lt;/code&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Breaking down the problem with P.R.E.P.
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Parameters&lt;/u&gt;&lt;br&gt;
The function expects one parameter: an array of ones and zeroes of any given length.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Returns&lt;/u&gt;&lt;br&gt;
The function should return one value: the integer representation of the binary inside the array.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;br&gt;
&lt;em&gt;All test cases provided can be found in the instructions.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;em&gt;See pseudo code section for each solution&lt;/em&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Solution 1: Parsing a binary string
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Convert array to string.
2) Convert the string to an integer by parsing it.
3) Return the integer.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;const&lt;/span&gt; &lt;span class="nx"&gt;binaryArrayToNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&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="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Notes&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1) Unlike the solutions from kata 1, all the solutions in this kata use the ES6 &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions"&gt;arrow function&lt;/a&gt; syntax. &lt;/p&gt;

&lt;p&gt;2) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join"&gt;&lt;code&gt;.join()&lt;/code&gt; array method&lt;/a&gt; is used to convert the array into a string. It concatenates the array elements into a string using either commas to separate the array values inside the string (default) or by using the separator specified inside the parenthesis. In this case all the numbers are joined together without a comma or any spaces between the numbers. &lt;/p&gt;

&lt;p&gt;3) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt"&gt;&lt;code&gt;parseInt()&lt;/code&gt; function&lt;/a&gt; receives two parameters: the string to parse and the radix that will be used for parsing - in our case 2 for binary. &lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 2: Reducing the value with math
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Start with a sum (accumulator) value of 0.
2) Multiple the accumulator by 2 and add 1 each iteration of the loop.
3) Return the accumulated value.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;const&lt;/span&gt; &lt;span class="nx"&gt;binaryArrayToNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;arr&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;cur&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;acc&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="nx"&gt;cur&lt;/span&gt;&lt;span class="p"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Notes&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce"&gt;&lt;code&gt;.reduce()&lt;/code&gt; array method&lt;/a&gt; is used to "loop over" an array, executing a callback function on each element of the array. The callback function has access to both the current element in the array and the previous value, which is an accumulation of all the executed calculations combined (often called the accumulator). This sum or accumulator value can be passed a default value, which is specified after the comma (in this case the default value is &lt;code&gt;0&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;2) Since the &lt;code&gt;.()reduce&lt;/code&gt; method essentially loops over each item in the array, it takes more time to execute than the first solution, which has the same execution time regardless of the array length. While the difference in time will be rather small because of how fast execution time is nowadays, it is still something to take into account, especially when dealing with longer arrays. Solutions that can operate in constant time - meaning independent of the array length - are more favorable than solutions that take more time depending on array length.  &lt;/p&gt;




&lt;p&gt;&lt;em&gt;No third solution for this kata will be provided. There are technically other ways to solve this challenge, but they are much more difficult to understand and/or have significant downsides, which make them less desirable as a solution.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Kata 3: Shortest Word
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Instructions
&lt;/h3&gt;

&lt;p&gt;Simple, given a string of words, return the length of the shortest word(s).&lt;/p&gt;

&lt;p&gt;String will never be empty and you do not need to account for different data types.&lt;/p&gt;




&lt;h3&gt;
  
  
  Breaking down the problem with P.R.E.P.
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Parameters&lt;/u&gt;&lt;br&gt;
The function expects one parameter: a string of words.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Returns&lt;/u&gt;&lt;br&gt;
The function should return one value: the length of the shortest word in the string.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;br&gt;
The following test cases are provided by CodeWars.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;("bitcoin take over the world maybe who knows perhaps"), 3
("turns out random test cases are easier than writing basic ones"), 3
("Let's travel abroad shall we"), 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;The string of words between the parenthesis is the string passed to the function, followed by the number that should be returned from the function.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;em&gt;See pseudo code section for each solution&lt;/em&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Solution 1: Using a for loop
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Create an array of the words contained in the string.
2) Declare a new variable with a value of the first word's length.
3) Loop over each word in the array. 
4) Check if word's length is smaller than the value of the variable.
5) If it is, set the word's length as the new value of the variable.
6) Return the variable's value.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;findShort&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&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="s1"&gt; &lt;/span&gt;&lt;span class="dl"&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;shortest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&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;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;arr&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&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;length&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;shortest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;shortest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&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;length&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;shortest&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;&lt;strong&gt;&lt;em&gt;Notes&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split"&gt;&lt;code&gt;.split()&lt;/code&gt; array method&lt;/a&gt; is used to convert the string into an array of words. The string is split into substrings each time a space is encountered, which is not included in the substrings. &lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 2: Sorting the words by word length
&lt;/h3&gt;

&lt;p&gt;This solution uses a very similar approach as solution 3 of kata 1, except with one extra step (turning the string into an array) and the sorting is done based on word length.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;findShort&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="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="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="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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;a&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;-&lt;/span&gt; &lt;span class="nx"&gt;b&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="mi"&gt;0&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Notes&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Just like in the 3rd solution of kata 1, the first element in the array is selected once the array has been sorted. We then get the length of that word since we don't want to return the word itself, but its length.&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 3: Finding the min in an array of word lengths
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Create an array of the words contained in the string.
2) Create another array containing the length of each word.
3) Find the lowest number in that array.
4) Return it.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;findShort&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="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;min&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="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="s1"&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;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;word&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;word&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Notes&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map"&gt;&lt;code&gt;.map()&lt;/code&gt; array method&lt;/a&gt; is used to create a new array by looping over the original array and executing a function on each element inside the array. An arrow function is used in this solution, which can be read as &lt;code&gt;for each word in the array, return the length of the word&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;2) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min"&gt;&lt;code&gt;Math.min()&lt;/code&gt; function&lt;/a&gt; receives numbers as its parameter and returns the number with the lowest value out of those numbers. The numbers passed to it have to be separated by a comma and cannot be contained inside an array. &lt;/p&gt;

&lt;p&gt;3) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax"&gt;spread operator (...array)&lt;/a&gt; is used to turn the array of numbers into numbers that can be passed to the &lt;code&gt;Math.min()&lt;/code&gt; function.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;What solution did you implement?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;What solution did you find the most elegant?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;What solution did you have trouble understanding?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let me know, I'd love to hear from you!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I hope you found this article helpful.&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;Connect with me on ...&lt;br&gt;
&lt;a href="https://twitter.com/Nat_A_Number"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/NatGeyzenTech"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>codewars</category>
      <category>challenge</category>
    </item>
    <item>
      <title>Rainbow Drops Background Animation [No JS]</title>
      <dc:creator>Nat's Tech Notes</dc:creator>
      <pubDate>Wed, 29 Jun 2022 21:31:45 +0000</pubDate>
      <link>https://dev.to/nats_tech_notes/rainbow-drops-background-animation-no-js-1nbe</link>
      <guid>https://dev.to/nats_tech_notes/rainbow-drops-background-animation-no-js-1nbe</guid>
      <description>&lt;p&gt;I've been playing around with pure CSS/no JS background animations, inspired by all the beautiful creations that can be found on CodePen. &lt;/p&gt;

&lt;p&gt;Today I made a rainbow drops background animation that I'm really proud of. It was also my first time using Haml and SCSS - or any HTML/CSS preprocessors for that matter - so I learned a lot while making this (and had a ton of fun!). &lt;/p&gt;

&lt;p&gt;Hope you enjoy!&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/natgeyzentech/embed/rNdaaeP?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Connect with me&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://codepen.io/natgeyzentech"&gt;CodePen&lt;/a&gt;&lt;br&gt;
&lt;a href="https://twitter.com/Nat_A_Number"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/NatGeyzenTech"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>html</category>
      <category>css</category>
      <category>codepen</category>
    </item>
    <item>
      <title>Day 4/30 Days of CodeWars: JavaScript Edition</title>
      <dc:creator>Nat's Tech Notes</dc:creator>
      <pubDate>Thu, 16 Jun 2022 03:35:14 +0000</pubDate>
      <link>https://dev.to/nats_tech_notes/day-430-days-of-codewars-javascript-edition-44j5</link>
      <guid>https://dev.to/nats_tech_notes/day-430-days-of-codewars-javascript-edition-44j5</guid>
      <description>&lt;p&gt;&lt;strong&gt;CodeWars challenges solved&lt;/strong&gt;&lt;br&gt;
1) &lt;a href="https://www.codewars.com/kata/554b4ac871d6813a03000035/train/javascript"&gt;Highest and Lowest (7 kyu)&lt;/a&gt;&lt;br&gt;
2) &lt;a href="https://www.codewars.com/kata/555eded1ad94b00403000071/train/javascript"&gt;Sum of the first nth term of Series (7 kyu)&lt;/a&gt;&lt;br&gt;
3) &lt;a href="https://www.codewars.com/kata/563cf89eb4747c5fb100001b/train/javascript"&gt;Remove the minimum (7 kyu)&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Kata 1: Highest and Lowest
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Instructions
&lt;/h3&gt;

&lt;p&gt;In this little assignment you are given a string of space separated numbers, and have to return the highest and lowest number.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;highAndLow("1 2 3 4 5");  // return "5 1"
highAndLow("1 2 -3 4 5"); // return "5 -3"
highAndLow("1 9 3 4 -5"); // return "9 -5"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Notes&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;All numbers are valid &lt;code&gt;Int32&lt;/code&gt;, no need to validate them.&lt;/li&gt;
&lt;li&gt;There will always be at least one number in the input string.&lt;/li&gt;
&lt;li&gt;Output string must be two numbers separated by a single space, and highest number is first.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Breaking down the problem with P.R.E.P.
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Parameters&lt;/u&gt;&lt;br&gt;
The function expects one parameter: a string of one or more valid, space separated numbers.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Returns&lt;/u&gt;&lt;br&gt;
The function should return one value: a string with the highest number, followed by a single space and ending with the lowest number.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;br&gt;
The following test cases are provided by CodeWars.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;("8 3 -5 42 -1 0 0 -9 4 7 4 -4"), "42 -9"
("1 2 3"), "3 1"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;The string of numbers between the parentheses are the numbers passed to the function, followed by the string of numbers that should be returned from the function.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;em&gt;See pseudo code section for each solution&lt;/em&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Solution 1: Looping over the numbers
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Turn the string of numbers into an array of numbers.
2) Declare variable 'highest' and set it to the first number.
3) Declare a variable 'lowest' and set it to the first number.
4) Loop over the array starting at index 1.
5) Set 'highest' to the current number in the loop if it's higher.
6) Set 'lowest' the current number in the loop if it's lower.
7) Return a string of highest and lowest with a space in between.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;highAndLow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;numbers&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="s1"&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;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Number&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;highest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&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;lowest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&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;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;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&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;highest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;highest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&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;lt;&lt;/span&gt; &lt;span class="nx"&gt;lowest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;lowest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&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="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;highest&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;lowest&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;&lt;em&gt;Notes&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;1) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split"&gt;&lt;code&gt;.split()&lt;/code&gt; string method&lt;/a&gt; splits a string into substrings and returns an array of those substrings. The splitting is done based on the parameter provided when calling the method - in this case a single space signifying it should be split whenever a single space is encountered. &lt;/p&gt;

&lt;p&gt;2) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map"&gt;&lt;code&gt;.map()&lt;/code&gt; array method&lt;/a&gt; is used in combination with the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number"&gt;&lt;code&gt;Number&lt;/code&gt; object&lt;/a&gt; to convert the substrings returned from the &lt;code&gt;.split()&lt;/code&gt; method into actual numbers (instead of strings containing numbers). This is important to avoid errors when we do the comparisons inside the &lt;code&gt;for&lt;/code&gt; loop.&lt;/p&gt;

&lt;p&gt;3) When declaring the &lt;code&gt;highest&lt;/code&gt; and &lt;code&gt;lowest&lt;/code&gt; variables, we use the &lt;code&gt;let&lt;/code&gt; keyword, since their values will change. Both variables are initialized with a default value of whatever number is first in the array. This is done using the bracket notation - arr[0]. &lt;/p&gt;

&lt;p&gt;4) Unlike most loops when iterating over an array, the loop starts at index 1 instead of index 0 since we just want to compare if any values besides the first number in the array are higher or lower than the current &lt;code&gt;highest&lt;/code&gt; and &lt;code&gt;lowest&lt;/code&gt; value. We loop until the end of the array and increment the index by 1 each iteration. This is fairly standard procedure in cases like these. &lt;/p&gt;

&lt;p&gt;5) Since only one action/line of code is executed for each &lt;code&gt;if&lt;/code&gt; statement, the &lt;code&gt;{}&lt;/code&gt; can be omitted. &lt;/p&gt;

&lt;p&gt;6) Because of &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Type_coercion"&gt;type coercion&lt;/a&gt; in JavaScript, the &lt;code&gt;highest&lt;/code&gt; variable is converted to a string when the &lt;code&gt;' '&lt;/code&gt; is added to it and it remains a string when the &lt;code&gt;lowest&lt;/code&gt; variable is added.&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 2: Sorting the numbers
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Turn the string of numbers into an array of numbers.
2) Sort the array of numbers from lowest to highest.
3) Return a string with the last and first numbers of the array.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;highAndLow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sortedNums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;numbers&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="s1"&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;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;sortedNums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;sortedNums&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;-&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;sortedNums&lt;/span&gt;&lt;span class="p"&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;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&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;&lt;em&gt;Notes&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;1) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort"&gt;&lt;code&gt;.sort()&lt;/code&gt; array method&lt;/a&gt; loops over an array, sorts its values and returns the sorted array. In this case, it is passed a callback function that compares two numbers - &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; - and sorts them accordingly. So if &lt;code&gt;b&lt;/code&gt; is smaller than &lt;code&gt;a&lt;/code&gt;, the &lt;code&gt;b&lt;/code&gt; value will be pushed to the left of the &lt;code&gt;a&lt;/code&gt; value until all values have been sorted correctly.&lt;/p&gt;

&lt;p&gt;2) Inside the &lt;code&gt;return&lt;/code&gt; statement, a new array is created containing the last number in the &lt;code&gt;sortedNums&lt;/code&gt; array (&lt;code&gt;sortedNums[sortedNums - 1]&lt;/code&gt;) and the first number (&lt;code&gt;sortedNums[0]&lt;/code&gt;). That array is then converted into a string using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join"&gt;&lt;code&gt;.join()&lt;/code&gt; array method&lt;/a&gt;, which similar to the &lt;code&gt;.split()&lt;/code&gt; method receives a parameter signifying how the array should be joined into a string. &lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 3: Extracting the max and min number
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Turn the string of numbers into an array of numbers.
2) Get the max (highest) number out of all the numbers.
3) Get the min (lowest) number out of all the numbers.
4) Return a string containing the highest and lowest numbers.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;highAndLow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;numArr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;numbers&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="s1"&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;return&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;numArr&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;numArr&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&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;&lt;em&gt;Notes&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;1) A &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals"&gt;template literal&lt;/a&gt; is returned containing two expressions calculating the largest and smallest number in &lt;code&gt;numArr&lt;/code&gt;. Expressions and variables inside template literals are denoted with the &lt;code&gt;${code}&lt;/code&gt; syntax. &lt;/p&gt;

&lt;p&gt;2) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max"&gt;&lt;code&gt;Math.max()&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min"&gt;&lt;code&gt;Math.min()&lt;/code&gt;&lt;/a&gt; functions are used to return the largest and smallest numbers respectively from a list of numbers passed as parameters.&lt;/p&gt;

&lt;p&gt;3) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax"&gt;spread operator (...)&lt;/a&gt; has many use cases, but in this case is used to turn the array of numbers into individual arguments that are passed to the &lt;code&gt;Math.max()&lt;/code&gt; and &lt;code&gt;Math.min()&lt;/code&gt; functions. &lt;/p&gt;




&lt;h2&gt;
  
  
  Kata 2: Sum of the first nth term of Series
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Instructions
&lt;/h3&gt;

&lt;p&gt;Your task is to write a function which returns the sum of the following series up to nth term (parameter).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Series: 1 + 1/4 + 1/7 + 1/10 + 1/13 + 1/16 +...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Rules:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need to round the answer to 2 decimal places and return it as String.&lt;/li&gt;
&lt;li&gt;If the given value is 0 then it should return 0.00&lt;/li&gt;
&lt;li&gt;You will only be given Natural Numbers as arguments.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Examples:(Input --&amp;gt; Output)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 --&amp;gt; 1 --&amp;gt; "1.00"
2 --&amp;gt; 1 + 1/4 --&amp;gt; "1.25"
5 --&amp;gt; 1 + 1/4 + 1/7 + 1/10 + 1/13 --&amp;gt; "1.57"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Breaking down the problem with P.R.E.P.
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Parameters&lt;/u&gt;&lt;br&gt;
The function expects one parameter: a natural number representing the amount of numbers/fractions that should be added to the total sum.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Returns&lt;/u&gt;&lt;br&gt;
The function should return one value: a string containing a number. &lt;/p&gt;

&lt;p&gt;The number inside the string should be 0.00 if the argument the function is called with is 0. Otherwise, it should be a number rounded up to two decimal places. &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;br&gt;
The following test cases are provided by CodeWars. These do not include the ones mentioned in the instructions above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(3), "1.39"
(4), "1.49"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;The first number represents the nth number passed to the function as an argument, followed by the string that should be returned from the function.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;em&gt;See pseudo code section for each solution&lt;/em&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Solution 1: Looping n times to add to the sum
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Declare a variable 'sum' with a default value of 0.
2) Loop n amount of times to add the calculation to the sum.
3) Return the sum.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;SeriesSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&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;sum&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="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;n&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="nx"&gt;sum&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;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&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="p"&gt;}&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toFixed&lt;/span&gt;&lt;span class="p"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Notes&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;1) Each loop, a fraction is added to the sum value, which is calculated by multiplying the current index by 3 and then adding 1 to that. So the first iteration the fraction would be &lt;code&gt;1/1&lt;/code&gt; since &lt;code&gt;3 * 0 = 0 + 1 = 1&lt;/code&gt;, followed by &lt;code&gt;1/4&lt;/code&gt; since &lt;code&gt;3 * 1 = 3 + 1 = 4&lt;/code&gt; and so forth. However, if &lt;code&gt;n&lt;/code&gt; is 0, the loop won't iterate since &lt;code&gt;i&lt;/code&gt; must be smaller than &lt;code&gt;n&lt;/code&gt; for the loop to execute and &lt;code&gt;0&lt;/code&gt; is not smaller than &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;2) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed"&gt;&lt;code&gt;.toFixed()&lt;/code&gt; method&lt;/a&gt; is used to format the number to its correct amount of decimals, in this case 2. &lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 2: Reducing an array of n length to its sum
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Create an array of n items.
2) Loop over the array.
3) Each iteration, add the calculation to the sum value.
4) Return the sum.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;SeriesSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&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="p"&gt;[...&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&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;sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;curr&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;sum&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;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&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="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toFixed&lt;/span&gt;&lt;span class="p"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Notes&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;1) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array"&gt;Array object&lt;/a&gt; is used in combination with &lt;code&gt;[]&lt;/code&gt; and the spread syntax (seen in solution 3 of kata 1) to create an array holding n amount of &lt;code&gt;undefined&lt;/code&gt; values. The number of items the array should contain is passed to the object as a parameter.&lt;/p&gt;

&lt;p&gt;2) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce"&gt;&lt;code&gt;.reduce()&lt;/code&gt; array method&lt;/a&gt; is then used to loop over the newly created array and execute a &lt;code&gt;reducer&lt;/code&gt; callback function. The callback function can receive 4 parameters: the sum, also referred to as the &lt;code&gt;accumulator&lt;/code&gt; or previous value, the current value, a.k.a. the value in the current iteration of the loop, the index and the array object which can access the array itself. Not all parameters need to be used - and in fact often times only the first two are - but they do always occur in the same order. Since we need access to the index parameter, the 2nd parameter is also mentioned, even though it is not actually used.&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 3: Recursively calculating the sum
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Return the formatted sum if the recursive base case is reached.
2) Otherwise return the recursive function and sum calculation.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;SeriesSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sum&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;n&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;sum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toFixed&lt;/span&gt;&lt;span class="p"&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="nx"&gt;SeriesSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&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;sum&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;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;n&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Notes&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;1) A &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator"&gt;conditional ternary operator&lt;/a&gt; is an alternative to an if else statement. It executes the code after the &lt;code&gt;?&lt;/code&gt; if the condition specified is met and the code after the &lt;code&gt;:&lt;/code&gt; it's not met. &lt;/p&gt;

&lt;p&gt;2) A recursive function is used to calculate the sum. &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Recursion"&gt;Recursion&lt;/a&gt; can be a rather hard concept to grasp. Essentially, a recursive function is a function that calls itself inside of itself. Since this basically creates a loop, a recursive function always needs a base case that specifies when the function should stop calling itself. The recursive function in this example first calls itself with the &lt;code&gt;n&lt;/code&gt; value. Each subsequent iteration, it subtracts 1 from &lt;code&gt;n&lt;/code&gt; until the base case is reached, in this case until &lt;code&gt;n&lt;/code&gt; reaches &lt;code&gt;0&lt;/code&gt;. It then stops calling itself, exiting the loop and returns a value, the formatted sum value.&lt;/p&gt;




&lt;h2&gt;
  
  
  Kata 3: Remove the minimum
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Instructions
&lt;/h3&gt;

&lt;p&gt;The museum of incredible dull things wants to get rid of some exhibitions. Miriam, the interior architect, comes up with a plan to remove the most boring exhibitions. She gives them a rating, and then removes the one with the lowest rating.&lt;/p&gt;

&lt;p&gt;However, just as she finished rating all exhibitions, she's off to an important fair, so she asks you to write a program that tells her the ratings of the items after one removed the lowest one. Fair enough.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task&lt;/strong&gt;&lt;br&gt;
Given an array of integers, remove the smallest value. Do not mutate the original array/list. If there are multiple elements with the same value, remove the one with a lower index. If you get an empty array/list, return an empty array/list.&lt;/p&gt;

&lt;p&gt;Don't change the order of the elements that are left.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* Input: [1,2,3,4,5], output= [2,3,4,5]
* Input: [5,3,2,1,4], output = [5,3,2,4]
* Input: [2,2,1,2,1], output = [2,2,2,1]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Breaking down the problem with P.R.E.P.
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Parameters&lt;/u&gt;&lt;br&gt;
The function expects one parameter: an array of integers.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Returns&lt;/u&gt;&lt;br&gt;
The function should return one value: a new array of integers that does not contain (the first instance of) the lowest value in the original array. &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;br&gt;
&lt;em&gt;The test cases provided by CodeWars are the same ones mentioned in the examples above in the instructions.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;em&gt;See pseudo code section for each solution&lt;/em&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Solution 1: Pushing numbers except smallest into a new array
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Find the index of the smallest number.
2) Create a new variable holding an empty array.
3) Loop over the array of numbers provided as an argument.
4) Push the number to the new array if its index isn't the index 
   of the smallest number.
5) Return the new array.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;removeSmallest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;smallestIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
  &lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;number&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="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;!==&lt;/span&gt; &lt;span class="nx"&gt;smallestIndex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;newArray&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;number&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;newArray&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;&lt;em&gt;Notes&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;1) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf"&gt;&lt;code&gt;.indexOf()&lt;/code&gt; method&lt;/a&gt; returns the first index at which the element specified within the method can be found within the array. It returns &lt;code&gt;-1&lt;/code&gt; if the element is not found.&lt;/p&gt;

&lt;p&gt;2) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach"&gt;&lt;code&gt;.forEach&lt;/code&gt; array method&lt;/a&gt; loops over a given array and executes a function on each of its elements. &lt;/p&gt;

&lt;p&gt;3) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push"&gt;&lt;code&gt;.push()&lt;/code&gt; array method&lt;/a&gt; adds an element to the end of the given array. It is used inside the &lt;code&gt;.forEach()&lt;/code&gt; loop to add the number of the current iteration inside the loop to the new array if its index does not match the index of the (first) lowest number in the original array.&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 2: Filtering out the smallest number by index
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Find the index of the smallest number.
2) Return a new array containing all elements except the (first) 
   smallest number.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;removeSmallest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;smallestIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;numbers&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;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;num&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="nx"&gt;smallestIndex&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;&lt;em&gt;Notes&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter"&gt;&lt;code&gt;.filter()&lt;/code&gt; array method&lt;/a&gt; returns a new array containing all elements that fulfill the condition specified within its callback function.  &lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 3: Slicing out the smallest number by index
&lt;/h3&gt;

&lt;p&gt;Pseudo code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Find the index of the smallest number.
2) Return a new array containing all elements before and after the 
   (first) smallest number.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;removeSmallest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;smallestIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;numbers&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="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;smallestIndex&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; 
         &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;numbers&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;smallestIndex&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notes&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice"&gt;&lt;code&gt;.slice()&lt;/code&gt; array method&lt;/a&gt; returns a new array containing a part - or slice - of the original array without modifying the original array. It receives two parameters: the index at which it should start copying and the first index that should be excluded from the copy. &lt;/p&gt;




&lt;p&gt;&lt;strong&gt;What solution did you implement?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;What solution did you find the most elegant?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;What solution did you have trouble understanding?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let me know, I'd love to hear from you!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I hope you found this article helpful.&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;Connect with me on ...&lt;br&gt;
&lt;a href="https://twitter.com/Nat_A_Number"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/NatGeyzenTech"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>codewars</category>
      <category>challenge</category>
    </item>
    <item>
      <title>Day 3/30 Days of CodeWars: JavaScript Edition</title>
      <dc:creator>Nat's Tech Notes</dc:creator>
      <pubDate>Mon, 06 Jun 2022 17:35:29 +0000</pubDate>
      <link>https://dev.to/nats_tech_notes/day-330-days-of-codewars-javascript-edition-4ch8</link>
      <guid>https://dev.to/nats_tech_notes/day-330-days-of-codewars-javascript-edition-4ch8</guid>
      <description>&lt;p&gt;&lt;strong&gt;CodeWars challenges solved&lt;/strong&gt;&lt;br&gt;
1) &lt;a href="https://www.codewars.com/kata/55cbc3586671f6aa070000fb/train/javascript"&gt;Grasshopper - Check for factor (8 kyu)&lt;/a&gt;&lt;br&gt;
2) &lt;a href="https://www.codewars.com/kata/56b1f01c247c01db92000076/train/javascript"&gt;Double Char (8 kyu)&lt;/a&gt;&lt;br&gt;
3) &lt;a href="https://www.codewars.com/kata/57a0885cbb9944e24c00008e/train/javascript"&gt;Remove exclamation marks (8 kyu)&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Kata 1: Grasshopper - Check for factor
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Instructions
&lt;/h3&gt;

&lt;p&gt;This function should test if the &lt;code&gt;factor&lt;/code&gt; is a factor of &lt;code&gt;base&lt;/code&gt;. Return &lt;code&gt;true&lt;/code&gt; if it is a factor or &lt;code&gt;false&lt;/code&gt; if it is not.&lt;/p&gt;

&lt;p&gt;Factors are numbers you can multiply together to get another number.&lt;/p&gt;

&lt;p&gt;2 and 3 are factors of 6 because: &lt;code&gt;2 * 3 = 6&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can find a factor by dividing numbers. If the remainder is 0 then the number is a factor.&lt;/li&gt;
&lt;li&gt;You can use the mod operator (%) in most languages to check for a remainder&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example 2 is not a factor of 7 because: &lt;code&gt;7 % 2 = 1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note: &lt;code&gt;base&lt;/code&gt; is a non-negative number, &lt;code&gt;factor&lt;/code&gt; is a positive number.&lt;/p&gt;


&lt;h3&gt;
  
  
  Breaking down the problem with P.R.E.P.
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Parameters&lt;/u&gt;&lt;br&gt;
The function expects two parameters: two numbers, one of which is the &lt;code&gt;base&lt;/code&gt; number and one that might or might not be the &lt;code&gt;factor&lt;/code&gt; number. &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Returns&lt;/u&gt;&lt;br&gt;
The function should return a &lt;code&gt;Boolean&lt;/code&gt; value: &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the &lt;code&gt;base&lt;/code&gt; parameter can be divided by the &lt;code&gt;factor&lt;/code&gt; parameter without returning a decimal number, it should return &lt;code&gt;true&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Otherwise, it should return &lt;code&gt;false&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;br&gt;
The following test cases are provided by CodeWars.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(10,2), true
(63,7), true
(2450,5), true
(24612,3), true
(9,2), false
(653,7), false
(2453,5), false
(24617,3), false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;The numbers between the parenthesis are the base and factor arguments passed to the function, followed by the value that should be returned from the function.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;em&gt;See pseudo code section for each solution&lt;/em&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Solution 1: Checking if quotient is an integer
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Check if dividing base by factor returns an integer.
2) If it does, return true.
3) Else, return false.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;checkForFactor&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;base&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;factor&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="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;base&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;factor&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;p&gt;&lt;em&gt;Notes&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;1) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder"&gt;modulo/remainder (%) operator&lt;/a&gt; mentioned in the instructions can be a bit hard to understand for beginners. So instead of checking for the remainder of the division, we check if the quotient - a.k.a. the result of the division - is an integer using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger"&gt;&lt;code&gt;Number.isInteger()&lt;/code&gt; method&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;2) As shown in the next solution, using if/else statements like this is actually unnecessary since the condition itself already evaluates to &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;. However, it's not uncommon for beginners to write it out like this, since it's easy to read and understand the code.&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 2: Short-hand of solution 1
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Check the quotient of base divided by the factor.
2) Evaluate if the quotient is an integer.
3) Return the result of that evaluation.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;checkForFactor&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;base&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;factor&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="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;base&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;factor&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;&lt;em&gt;Notes&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;As mentioned in solution 1, there is actually no need to use if/else statements just to return &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt; values. The condition specified inside the if statement itself evaluates to &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt; so when we return the condition itself, we actually return the result of evaluating that condition. &lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 3: Conditional return with modulo operator
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Check the remainder of base divided by the factor.
2) Evaluate if the remainder is (strictly) equal to 0.
3) Return the result of that evaluation.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;checkForFactor&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;base&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;factor&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;base&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="nx"&gt;factor&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Notes&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;1) The modulo or remainder operator returns the remainder of the first number divided by the second number. For example in &lt;code&gt;23 % 3&lt;/code&gt;, &lt;code&gt;23&lt;/code&gt; cannot be evenly divided by &lt;code&gt;3&lt;/code&gt;, but &lt;code&gt;21&lt;/code&gt; can (&lt;code&gt;3 * 7&lt;/code&gt;) and &lt;code&gt;23 - 21 = 2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;2) If the remainder is 0, that means the &lt;code&gt;base&lt;/code&gt; can evenly be divided by the &lt;code&gt;factor&lt;/code&gt;, meaning the &lt;code&gt;factor&lt;/code&gt; parameter is an actual &lt;code&gt;factor&lt;/code&gt; (and should therefor return &lt;code&gt;true&lt;/code&gt;).&lt;/p&gt;




&lt;h2&gt;
  
  
  Kata 2: Double Char
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Instructions
&lt;/h3&gt;

&lt;p&gt;Given a string, you have to return a string in which each character (case-sensitive) is repeated once.&lt;/p&gt;

&lt;p&gt;Examples (Input -&amp;gt; Output):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* "String"      -&amp;gt; "SSttrriinngg"
* "Hello World" -&amp;gt; "HHeelllloo  WWoorrlldd"
* "1234!_ "     -&amp;gt; "11223344!!__  "
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Good Luck!&lt;/p&gt;




&lt;h3&gt;
  
  
  Breaking down the problem with P.R.E.P.
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Parameters&lt;/u&gt;&lt;br&gt;
The function expects one parameter: a string. &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Returns&lt;/u&gt;&lt;br&gt;
The function should return one value: a string where each character in the string appears twice in a row.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;br&gt;
The following test cases are provided by CodeWars.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;("abcd"), "aabbccdd"
("Adidas"), "AAddiiddaass"
("1337"), "11333377"
("illuminati"), "iilllluummiinnaattii"
("123456"), "112233445566"
("%^&amp;amp;*("), "%%^^&amp;amp;&amp;amp;**(("
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;The string passed to the function as an argument is found between the parenthesis, followed by the string that should be returned from the function.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;em&gt;See pseudo code section for each solution&lt;/em&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Solution 1: Using a for loop
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Create a variable initialized as an empty string.
2) Loop over all the characters in the string.
3) Add the character to the string variable twice.
4) Return the string variable.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;doubleChar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&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;doubleString&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;str&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="nx"&gt;doubleString&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;str&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;str&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="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;doubleString&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;&lt;em&gt;Notes&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;1) Strings, just like arrays, start at index 0 so to avoid off-by-one errors, we also start the loop at index 0. &lt;/p&gt;

&lt;p&gt;2) Each iteration of the loop, the &lt;code&gt;doubleString&lt;/code&gt; variable is set to the current value of &lt;code&gt;doubleString&lt;/code&gt; and the character currently being iterated over in the loop is added to that twice. This is done with the help of the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Addition_assignment"&gt;addition assignment operator (+=)&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;3) This solution is somewhat similar &lt;a href="https://dev.to/nats_tech_notes/day-130-days-of-codewars-javascript-edition-3560#:~:text=the%20%27sum%27%20variable-,JavaScript%20code,-function%20positiveSum(arr)"&gt;Day 1, kata 1, solution 1&lt;/a&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 2: String to array back to string
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Turn string into array.
2) Loop over array.
3) Create new array with each character appearing twice.
4) Turn array back into string.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;doubleChar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&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;str&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="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;char&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;char&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;repeat&lt;/span&gt;&lt;span class="p"&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="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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Notes&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;1) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split"&gt;&lt;code&gt;.split()&lt;/code&gt; string method&lt;/a&gt; splits a string into substrings and returns an array of those substrings. It takes a parameter that specifies how the string should be split. In our case the empty string parameter indicates it should split each character into its own substring.&lt;/p&gt;

&lt;p&gt;2) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map"&gt;&lt;code&gt;.map()&lt;/code&gt; array method&lt;/a&gt; executes a function on each element in the array and returns a new array with the results of calling that function on each element.&lt;/p&gt;

&lt;p&gt;3) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat"&gt;&lt;code&gt;.repeat()&lt;/code&gt; string method&lt;/a&gt; takes a number as its parameter, concatenates the string the method was called on the amount of times specified in that parameter and then returns that as a new string. &lt;/p&gt;

&lt;p&gt;4) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join"&gt;.&lt;code&gt;join()&lt;/code&gt; array method&lt;/a&gt; is pretty much the opposite of the .&lt;code&gt;split()&lt;/code&gt; string method and - as the name suggest - joins elements of an array into a new string. It takes a parameter specifying how the array elements should be joined, in our case the empty string signifying each character should be joined without any white-space or other characters in between. &lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 3: Using regular expressions
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Replace each character by the character twice.
2) Return the result of replacing all characters.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;doubleChar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&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;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;.&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;$1$1&lt;/span&gt;&lt;span class="dl"&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;&lt;em&gt;Notes&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;1) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace"&gt;&lt;code&gt;.replace()&lt;/code&gt; string method &lt;/a&gt; replaces the characters, text or patterns specified in the first parameter by the text, characters or patterns in the second parameter.&lt;/p&gt;

&lt;p&gt;2) &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions"&gt;Regular expressions&lt;/a&gt; are used in strings to find, match or replace certain patterns inside the string. They always consist of &lt;code&gt;/ /&lt;/code&gt; with the pattern specified in between.&lt;/p&gt;

&lt;p&gt;3)&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Groups_and_Ranges#:~:text=(x)-,Capturing%20group,-%3A%20Matches%20x"&gt; Capture groups&lt;/a&gt; are used here to not just find the matching pattern, but remember it. A pattern in a capture group is surrounded by &lt;code&gt;()&lt;/code&gt; and can also be accessed using the &lt;code&gt;$&lt;/code&gt; symbol, followed by the number of the capture group - in this case 1 since there is only 1 capture group in the regex.&lt;/p&gt;

&lt;p&gt;4) The &lt;code&gt;.&lt;/code&gt; inside the capture group is known as a wildcard character and can match any character except for line terminators such as &lt;code&gt;\n&lt;/code&gt; which indicates a new line. &lt;/p&gt;

&lt;p&gt;5) The &lt;code&gt;/g&lt;/code&gt; flag stands for global, If this flag wasn't used, the regex would only match to the first character and replace it, but not replace any subsequent characters. The global flag ensures it matches with ALL characters it can match to, in this case any characters in the string.&lt;/p&gt;




&lt;h2&gt;
  
  
  Kata 3: Remove exclamation marks
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Instructions
&lt;/h3&gt;

&lt;p&gt;Write function RemoveExclamationMarks which removes all exclamation marks from a given string.&lt;/p&gt;




&lt;h3&gt;
  
  
  Breaking down the problem with P.R.E.P.
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Parameters&lt;/u&gt;&lt;br&gt;
The function expects one parameter: a string.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Returns&lt;/u&gt;&lt;br&gt;
The function should return one value: a string containing no exclamation marks.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;br&gt;
The following test cases are provided by CodeWars.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;("Hello World!"), "Hello World"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;The string between the parenthesis is the argument passed to the function, followed by the string that should be returned from the function.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;em&gt;No pseudo code for this kata&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This coding challenge is fairly similar to the previous kata with some minor differences, so the solutions will be fairly similar, with some minor changes (hence why there won't be any pseudo code either). I'll be focusing mostly on the changes between these two kata.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 1: Using a for loop
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;removeExclamationMarks&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;newString&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;if&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="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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;newString&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;i&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;newString&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;&lt;em&gt;Notes&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;Instead of adding each character twice to our &lt;code&gt;newString&lt;/code&gt; variable like in kata 2 solution 1, we check if the character in the current iteration is an exclamation mark. If it's not, we add the character to the &lt;code&gt;newString&lt;/code&gt; variable. If it is, it wil essentially skip this iteration and continue to the next one.&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 2: String to array back to string
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;removeExclamationMarks&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="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;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;char&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;char&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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;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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Notes&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;Instead of using the &lt;code&gt;.map()&lt;/code&gt; array method like in kata 2 solution 2, we are using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter"&gt;&lt;code&gt;.filter()&lt;/code&gt; array method&lt;/a&gt;. It takes a callback function which specifies how the array should be filtered - in this case any character that is not an exclamation mark. It returns a new array with all elements that fulfill the condition specified inside the callback function.&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 3: Using regular expressions
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;removeExclamationMarks&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="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/!/g&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Notes&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;This is basically a simplified version of kata 2 solution 3 and it replaces any exclamation marks with an empty string, meaning exclamations marks just end up being "cut out" of the string.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;What solution did you implement?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;What solution did you find the most elegant?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;What solution did you have trouble understanding?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let me know, I'd love to hear from you!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I hope you found this article helpful.&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;Connect with me on ...&lt;br&gt;
&lt;a href="https://twitter.com/Nat_A_Number"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/NatGeyzenTech"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>codewars</category>
      <category>challenge</category>
    </item>
    <item>
      <title>Day 2/30 Days of CodeWars: JavaScript Edition</title>
      <dc:creator>Nat's Tech Notes</dc:creator>
      <pubDate>Wed, 01 Jun 2022 20:36:01 +0000</pubDate>
      <link>https://dev.to/nats_tech_notes/day-230-days-of-codewars-javascript-edition-2n7f</link>
      <guid>https://dev.to/nats_tech_notes/day-230-days-of-codewars-javascript-edition-2n7f</guid>
      <description>&lt;p&gt;&lt;strong&gt;CodeWars challenges solved&lt;/strong&gt;&lt;br&gt;
1) &lt;a href="https://www.codewars.com/kata/5772da22b89313a4d50012f7/train/javascript"&gt;Grasshopper - Personalized Message (8 kyu)&lt;/a&gt;&lt;br&gt;
2) &lt;a href="https://www.codewars.com/kata/557cd6882bfa3c8a9f0000c1/train/javascript"&gt;Parse nice int from char problem (8 kyu)&lt;/a&gt;&lt;br&gt;
3) &lt;a href="https://www.codewars.com/kata/577bd026df78c19bca0002c0/train/javascript"&gt;Correct the mistakes of the character recognition software (8 kyu)&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Kata 1: Grasshopper - Personalized Message
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Instructions
&lt;/h3&gt;

&lt;p&gt;Create a function that gives a personalized greeting. This function takes two parameters: &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;owner&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Use conditionals to return the proper message:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;name equals owner =&amp;gt; 'Hello boss'&lt;/li&gt;
&lt;li&gt;otherwise =&amp;gt; 'Hello guest'&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  Breaking down the problem
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Parameters&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;As mentioned in the instructions above, the function expects two parameters: &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;owner&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Based on the test cases, both are expected to be (valid) strings, though in actuality they might not be.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Returns&lt;/u&gt;&lt;br&gt;
The function should return one value: a string.&lt;/p&gt;

&lt;p&gt;What string should be returned depends on whether or not the &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;owner&lt;/code&gt; match &lt;em&gt;(see instructions above)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;br&gt;
The following test cases are provided by CodeWars.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;('Daniel', 'Daniel'), 'Hello boss'
('Greg', 'Daniel'), 'Hello guest'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;The first two values are the arguments that will be passed to the function, followed by the message that should be returned.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;This coding challenge is fairly similar to &lt;a href="https://dev.to/nats_tech_notes/day-130-days-of-codewars-javascript-edition-3560#:~:text=Kata%203%3A%20Keep%20up%20the%20hoop"&gt;the third kata solved yesterday&lt;/a&gt; with some minor differences. So instead of reiterating through the same solutions mentioned in that kata, I'll be providing some variations to those solutions as well as diving deeper into error handling.&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 1: Basic implementations without error handling
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;The following implementations assume that the arguments passed to the function are valid strings (like in the test cases provided by CodeWars).&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;
  &lt;strong&gt;Variant 1: using if/else statements&lt;/strong&gt;
  &lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;owner&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;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;owner&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello boss&lt;/span&gt;&lt;span class="dl"&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;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello guest&lt;/span&gt;&lt;span class="dl"&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;This is the easiest and probably most common implementation.&lt;/p&gt;


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




&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;Variant 2: using an if statement only&lt;/strong&gt;
  &lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;owner&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;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello boss&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello guest&lt;/span&gt;&lt;span class="dl"&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;This is a similar approach to variant 1, with 2 main differences:&lt;/p&gt;

&lt;p&gt;1) The &lt;code&gt;if statement&lt;/code&gt; is written on 1 line and the &lt;code&gt;{}&lt;/code&gt; after the statement's condition have been omitted. This is valid code for one-line conditional statements, though it is usually recommended to add the &lt;code&gt;{}&lt;/code&gt;. It is also important to note that (most) &lt;a href="https://gomakethings.com/javascript-linters/"&gt;JavaScript linters&lt;/a&gt; will add the &lt;code&gt;{}&lt;/code&gt; when formatting code if they have been omitted.&lt;/p&gt;

&lt;p&gt;2) There is no &lt;code&gt;else statement&lt;/code&gt;. It has been replaced by another &lt;code&gt;return&lt;/code&gt; outside of the &lt;code&gt;if statement&lt;/code&gt;. This works because the function can only execute 1 &lt;code&gt;return&lt;/code&gt; so if it does not execute the code inside the &lt;code&gt;if statement&lt;/code&gt;, it will return the string specified outside of the &lt;code&gt;if statement&lt;/code&gt;.&lt;/p&gt;





&lt;/p&gt;

&lt;p&gt;
  &lt;strong&gt;Variant 3: using a conditional ternary operator&lt;/strong&gt;
  &lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;owner&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;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello boss&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello guest&lt;/span&gt;&lt;span class="dl"&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;

&lt;p&gt;
  &lt;strong&gt;Variant 4: using template literal syntax&lt;/strong&gt;
  &lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;owner&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="s2"&gt;`Hello &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;boss&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;guest&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals"&gt;Template literals&lt;/a&gt; are useful to create complicated and multi-line strings that can include single and double quotes, as well as variables and expressions (like the ternary operator above). It also eliminates the need to concatenate strings using the &lt;code&gt;+&lt;/code&gt; operator. &lt;/p&gt;



&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 2: Handling input that is not a string
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;The implementations from solution 1 pass the test cases provided by CodeWars, but they also pass when the arguments provided are &lt;code&gt;numbers&lt;/code&gt;, &lt;code&gt;null&lt;/code&gt;, &lt;code&gt;undefined&lt;/code&gt;, &lt;code&gt;objects&lt;/code&gt; and &lt;code&gt;arrays&lt;/code&gt; for examples. This is likely not behavior we would want in a real life scenario, so let's add some code to handle cases where one or both of the arguments passed are not strings.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;br&gt;
The following test cases have been added by me:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(2, 5), 'Invalid input'
({}, []), 'Invalid input'
(null, 'undefined'), 'Invalid input'
('null', 'undefined'), 'Hello guest'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;
  &lt;strong&gt;Variant 1: using if/else if statements&lt;/strong&gt;
  &lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isValidName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isValidOwner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isValidArgs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;isValidName&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;isValidOwner&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="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isValidArgs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Invalid input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;else&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;isValidArgs&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello boss&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello guest&lt;/span&gt;&lt;span class="dl"&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;&lt;em&gt;Notes&lt;/em&gt;: &lt;/p&gt;

&lt;p&gt;1) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof"&gt;typeof operator&lt;/a&gt; is used to verify that the &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;owner&lt;/code&gt; arguments are &lt;code&gt;strings&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;2) It is common practice to start variables storing a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean"&gt;Boolean&lt;/a&gt; value with 'is'.&lt;/p&gt;

&lt;p&gt;3) The 3 first lines can easily be reworked into 1 line. I just chose to split them up for this article to make it a little easier to follow along with what is going on.&lt;/p&gt;

&lt;p&gt;4) The &lt;code&gt;if statement&lt;/code&gt; uses the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_NOT"&gt;logical not (!) operator&lt;/a&gt; to return the string &lt;code&gt;"Invalid input"&lt;/code&gt; if &lt;code&gt;isValidArgs&lt;/code&gt; is false (meaning one or both of the arguments are not strings). &lt;/p&gt;





&lt;/p&gt;

&lt;p&gt;
  &lt;strong&gt;Variant 2: using a nested ternary operator&lt;/strong&gt;
  &lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// variable declarations (deleted for legibility) &lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isValidParams&lt;/span&gt; 
    &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Invalid input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; 
    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;isValidParams&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt; 
      &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello boss&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello guest&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 3: Handling invalid input/strings
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Besides arguments that aren't strings, there is another (edge) case that we want to consider: invalid strings such as empty strings and strings containing only white-space. Depending on the real-world context our code is implemented in, the rules on what is considered an invalid string might be less or more strict, but for the purposes of this exercise, we'll assume that both names (first, last and full) and usernames are allowed.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
  &lt;strong&gt;Test cases and solution&lt;/strong&gt;
  &lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;('nats_tech_notes', 'nats_tech_notes'), 'Hello boss'
('@Nat_A_Number', '12345'), 'Hello guest'
('', ''), 'Invalid input'
(' ', ' '), 'Invalid input'
(3, 5), 'Invalid input'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The test cases above were added by me.&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;function&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;regex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/^&lt;/span&gt;&lt;span class="se"&gt;[\S]\w&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isValidName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; 
                      &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isValidOwner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                       &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isValidArgs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;isValidName&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;isValidOwner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// deleted code: same code from solution 2&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Notes&lt;/em&gt;: &lt;/p&gt;

&lt;p&gt;1) To test the validity of the string, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions"&gt;regular expressions&lt;/a&gt; are used. &lt;/p&gt;

&lt;p&gt;2) The regular expression starts with the &lt;code&gt;^&lt;/code&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Assertions"&gt;assertion&lt;/a&gt; symbol, signifying the beginning of the string, followed by the &lt;code&gt;\S&lt;/code&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes"&gt;character class&lt;/a&gt; to indicate no white-space. This ensures the string cannot start with or contain only white-space. It also contains the &lt;code&gt;\w&lt;/code&gt; character class to verify the string contains at least 1 alphanumerical character. This combination allows for full/multiple names to be used which will contain white-space between each name.&lt;/p&gt;


&lt;/p&gt;








&lt;h2&gt;
  
  
  Kata 2: Parse nice int from char problem
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Instructions
&lt;/h3&gt;

&lt;p&gt;You ask a small girl,"How old are you?" She always says, "x years old", where x is a random number between 0 and 9.&lt;/p&gt;

&lt;p&gt;Write a program that returns the girl's age (0-9) as an integer.&lt;/p&gt;

&lt;p&gt;Assume the test input string is always a valid string. For example, the test input may be "1 year old" or "5 years old". The first character in the string is always a number.&lt;/p&gt;




&lt;h3&gt;
  
  
  Breaking down the problem
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Parameters&lt;/u&gt;&lt;br&gt;
The function expects 1 parameter: a string.&lt;/p&gt;

&lt;p&gt;The instructions specify the string will always be a valid string and the first character in the string will always be the age.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Returns&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;The function should return 1 value: a number, more specifically an integer.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;The following test cases are provided by CodeWars.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;("4 years old"), 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;The first value is the string that will be passed to the function, followed by the integer that should be returned.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 1: using parseInt()
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getAge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputString&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputString&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;&lt;em&gt;Notes&lt;/em&gt;: &lt;/p&gt;

&lt;p&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt"&gt;&lt;code&gt;parseInt()&lt;/code&gt; function&lt;/a&gt; receives a string and returns an integer number if a number is present inside the string. If no number is present, it returns &lt;code&gt;NaN&lt;/code&gt;. &lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 2: using Number()
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getAge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputString&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputString&lt;/span&gt;&lt;span class="p"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Notes&lt;/em&gt;: &lt;/p&gt;

&lt;p&gt;1) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number"&gt;&lt;code&gt;Number()&lt;/code&gt; function&lt;/a&gt; can convert values that are not numbers into numbers. &lt;/p&gt;

&lt;p&gt;2) Just like arrays, the bracket notation can be used with strings to select a character at the specified index (&lt;code&gt;string[index]&lt;/code&gt;). &lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 3: using regex and the unary operator
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getAge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputString&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;numChar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;inputString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\d&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;numChar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// alternatively:&lt;/span&gt;
  &lt;span class="c1"&gt;// return +inputString.match(/\d/);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Notes&lt;/em&gt;: &lt;/p&gt;

&lt;p&gt;1) Instead of the &lt;code&gt;.test()&lt;/code&gt; function used in kata 1, solution 3, we use the &lt;code&gt;.match()&lt;/code&gt; function to extract the part of the string that matches the regex pattern. &lt;/p&gt;

&lt;p&gt;2) The &lt;code&gt;\d&lt;/code&gt; character class is used to match digits.&lt;/p&gt;

&lt;p&gt;3) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unary_plus"&gt;&lt;code&gt;unary plus operator (+)&lt;/code&gt;&lt;/a&gt;, much like the &lt;code&gt;Number()&lt;/code&gt; function, converts values into numbers, if they aren't already numbers. &lt;/p&gt;




&lt;h2&gt;
  
  
  Kata 3: Correct the mistakes of the character recognition software
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Instructions
&lt;/h3&gt;

&lt;p&gt;When documents (especially pretty old ones written with a typewriter), are digitized character recognition software often make mistakes.&lt;/p&gt;

&lt;p&gt;Your task is correct the errors in the digitized text. You only have to handle the following mistakes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;S&lt;/code&gt; is misinterpreted as &lt;code&gt;5&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;O&lt;/code&gt; is misinterpreted as &lt;code&gt;0&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;I&lt;/code&gt; is misinterpreted as &lt;code&gt;1&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The test cases contain numbers only by mistake.&lt;/p&gt;




&lt;h3&gt;
  
  
  Breaking down the problem
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Parameters&lt;/u&gt;&lt;br&gt;
The function receives one parameter: a string.&lt;/p&gt;

&lt;p&gt;The string contains both letters and numbers.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Returns&lt;/u&gt;&lt;br&gt;
The function should return one value: a string containing only letters.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;br&gt;
The following test cases are provided by CodeWars.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"L0ND0N" =&amp;gt; "LONDON"
"DUBL1N" =&amp;gt; "DUBLIN"
"51NGAP0RE" =&amp;gt; "SINGAPORE"
"BUDAPE5T" =&amp;gt; "BUDAPEST"
PAR15" =&amp;gt; "PARIS"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Solution 1: Creating a new string from an array
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;correct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
  &lt;span class="nx"&gt;string&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;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;char&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;char&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;5&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;arr&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;S&lt;/span&gt;&lt;span class="dl"&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;else&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;char&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;arr&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;O&lt;/span&gt;&lt;span class="dl"&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;else&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;char&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;arr&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I&lt;/span&gt;&lt;span class="dl"&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;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;arr&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;char&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;arr&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Notes&lt;/em&gt;: &lt;/p&gt;

&lt;p&gt;1) A new empty array is initiated so letters can be pushed into it.&lt;/p&gt;

&lt;p&gt;2) The original string is then turned into an array using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split"&gt;&lt;code&gt;.split()&lt;/code&gt; method &lt;/a&gt;so we can loop over the array using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach"&gt;&lt;code&gt;.forEach&lt;/code&gt; array method&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;3) Inside the loop, we verify if the current character is one of the specified numbers and if it is, the correct letter is pushed into the array. If the character is already a letter, the letter is pushed into the array. &lt;/p&gt;

&lt;p&gt;4) We then turn the array back into a string using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join"&gt;&lt;code&gt;.join()&lt;/code&gt; method&lt;/a&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 2: Replacing each character separately
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;correct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string&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;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/5/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;S&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/0/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;O&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/1/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I&lt;/span&gt;&lt;span class="dl"&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;&lt;em&gt;Notes&lt;/em&gt;: &lt;/p&gt;

&lt;p&gt;1) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace"&gt;&lt;code&gt;.replace()&lt;/code&gt; method&lt;/a&gt;, as the name suggests, replaces the text/pattern specified in its first parameter with the text/pattern specified in the second parameter and returns a new string.&lt;/p&gt;

&lt;p&gt;2) The method is called 3 times on the same object (string) with the help of &lt;a href="https://www.geeksforgeeks.org/method-chaining-in-javascript/#:~:text=Method%20Chaining%20is%20a%20programming,in%20which%20it%20is%20called."&gt;method chaining&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;3) The &lt;code&gt;/g&lt;/code&gt; flag at the end of the regular expression stands for global and is used to match not just the first occurrence, but all occurrences in the string. &lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 3: Replacing all characters at once
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;correct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chars&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;5&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;S&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;O&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I&lt;/span&gt;&lt;span class="dl"&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;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;501&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;chars&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&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;&lt;em&gt;Notes&lt;/em&gt;: &lt;/p&gt;

&lt;p&gt;1) First an object is created to hold the incorrect number characters and their replacements. &lt;/p&gt;

&lt;p&gt;2) The &lt;code&gt;.replace()&lt;/code&gt; method is then used to replace all incorrect characters at once instead of one by one. To achieve this, a function is provided as the second parameter that grabs the correct replacement from the object. &lt;/p&gt;




&lt;p&gt;&lt;strong&gt;What solution did you implement?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;What solution did you find the most elegant?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;What solution did you have trouble understanding?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let me know, I'd love to hear from you!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I hope you found this article helpful.&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;Connect with me on ...&lt;br&gt;
&lt;a href="https://twitter.com/Nat_A_Number"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/NatGeyzenTech"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 1/30 Days of CodeWars: JavaScript Edition</title>
      <dc:creator>Nat's Tech Notes</dc:creator>
      <pubDate>Mon, 30 May 2022 08:25:52 +0000</pubDate>
      <link>https://dev.to/nats_tech_notes/day-130-days-of-codewars-javascript-edition-3560</link>
      <guid>https://dev.to/nats_tech_notes/day-130-days-of-codewars-javascript-edition-3560</guid>
      <description>&lt;p&gt;&lt;strong&gt;CodeWars challenges solved&lt;/strong&gt;&lt;br&gt;
1) &lt;a href="https://www.codewars.com/kata/5715eaedb436cf5606000381/train/javascript"&gt;Sum of positive (8 kyu)&lt;/a&gt;&lt;br&gt;
2) &lt;a href="https://www.codewars.com/kata/54edbc7200b811e956000556/train/javascript"&gt;Counting sheep (8 kyu)&lt;/a&gt;&lt;br&gt;
3) &lt;a href="https://www.codewars.com/kata/55cb632c1a5d7b3ad0000145/train/javascript"&gt;Keep up the hoop (8 kyu)&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Kata 1: Sum of positive
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Instructions
&lt;/h3&gt;

&lt;p&gt;You get an array of numbers, return the sum of all of the positives ones. Note: if there is nothing to sum, the sum is default to 0.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1,-4,7,12] =&amp;gt; 1 + 7 + 12 = 20
[] =&amp;gt; 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Breaking down the problem with P.R.E.P.
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Parameters&lt;/u&gt;&lt;br&gt;
The function expects one parameter: an array of numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The given array of numbers can ...
1) be empty 
2) contain only positive numbers 
3) contain only negative numbers 
4) contain a combination of both 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Returns&lt;/u&gt;&lt;br&gt;
The function should return one value: a number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The function should return 0 if ...
1) the array is empty
2) the array only contains negative numbers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The function should return a positive number if 
there is at least 1 positive number inside the array
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;br&gt;
The following test cases are provided by CodeWars.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1,2,3,4,5], 15
[1,-2,3,4,5], 13
[], 0
[-1,-2,-3,-4,-5],0
[-1,2,3,4,-5], 9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;The number following the array is the value/sum that should be returned.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;em&gt;See pseudo code section for each solution&lt;/em&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Solution 1: Using a for loop
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Declare a 'sum' variable.
2) Loop over the given array.
3) Check if the current number in the loop is positive.
4) If it is, add that number to the current value of 'sum'.
5) Return the 'sum' variable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;JavaScript code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function positiveSum(arr) {
  let sum = 0;
  for (let i = 0; i &amp;lt; arr.length; i++) {
    if (arr[i] &amp;gt; 0) {
      sum += arr[i];
    }
  }
  return sum;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Notes&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;1) The sum variable is declared with a default value of 0 to ensure that it returns 0 if the array is empty or does not contain any positive numbers.&lt;/p&gt;

&lt;p&gt;2) The loop starts at index 0 instead of 1 - just like an array - and continues to loop as long as the loop index is smaller than the array length to ensure no off-by-one errors occur.&lt;/p&gt;

&lt;p&gt;3) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#access_an_array_item_by_its_index"&gt;bracket notation&lt;/a&gt; - &lt;code&gt;arr[1]&lt;/code&gt; - is used to select the element in the array at the current loop index (so if the loop is at index 0, it selects the element in the array at index 0, meaning the first item in the array).&lt;/p&gt;

&lt;p&gt;4) The &lt;code&gt;+=&lt;/code&gt; operator is an &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Addition_assignment"&gt;addition assignment operator&lt;/a&gt; and is shorthand for &lt;code&gt;variable = variable + value&lt;/code&gt; (in this case &lt;code&gt;sum = sum + arr[i]&lt;/code&gt;). &lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 2: Using the filter() and reduce() array methods
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Create a new array containing only positive numbers.
2) Loop over the new array.
3) Sum up all values in the new array.
4) Return the 'sum' variable.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;JavaScript code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function positiveSum(arr) {
  return arr.filter(num =&amp;gt; num &amp;gt; 0)                   
            .reduce((sum, curr) =&amp;gt; sum + curr, 0);     
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Notes&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;1) Both the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter"&gt;filter()&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce"&gt;reduce()&lt;/a&gt; array methods are used to loop over arrays and receive a callback function as its parameter.&lt;/p&gt;

&lt;p&gt;2) The filter() callback function tests each element for a specified condition (like the if statement in solution 1) and the method creates a new array with all the elements that passed that test.&lt;/p&gt;

&lt;p&gt;3) The reduce() method returns a single value. The callback function specifies a calculation (like adding or subtracting) or action (like concatenation) to perform on each element, followed by an initial value (in this case &lt;code&gt;0&lt;/code&gt;). Each iteration, the previous (or initial) value of that calculation/action is passed to the current iteration until a single value remains.&lt;/p&gt;

&lt;p&gt;4) Both of these methods do not make any changes to the original array.&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This is the solution I submitted for this challenge. In my  opinion, it is an elegant solution that doesn't require a lot of code, but is still much easier to read and understand than the next solution.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  Solution 3: Using the reduce() array method only
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;This implementation combines the approaches of solution 1 and solution 2 into a single line of code inside the function, though it was spread over 2 lines in this article to avoid having a horizontal scroll bar in the code block below.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;JavaScript code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function positiveSum(arr) {
  return arr.reduce((sum, curr) =&amp;gt; 
    curr &amp;gt; 0 ? sum + curr : sum, 0);  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Notes&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;1) Similar to solution 1, we loop over all the elements in the given array, except using the reduce() array method instead of a for loop.&lt;/p&gt;

&lt;p&gt;2) The if statement from solution 1 is replaced by a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator"&gt;conditional ternary operator&lt;/a&gt; to check if the number is positive. If it is, it should return the value of the sum and add the current number to it. If it isn't a positive number, it should just return the  value of the sum for that iteration.&lt;/p&gt;




&lt;h2&gt;
  
  
  Kata 2: Counting sheep
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Instructions
&lt;/h3&gt;

&lt;p&gt;Consider an array/list of sheep where some sheep may be missing from their place. We need a function that counts the number of sheep present in the array (true means present).&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Example&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[true,  true,  true,  false,
  true,  true,  true,  true ,
  true,  false, true,  false,
  true,  false, false, true ,
  true,  true,  true,  true ,
  false, false, true,  true]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The correct answer would be &lt;code&gt;17&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Hint: Don't forget to check for bad values like &lt;code&gt;null&lt;/code&gt;/&lt;code&gt;undefined&lt;/code&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Breaking down the problem with P.R.E.P.
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Parameters&lt;/u&gt;&lt;br&gt;
The function expects one parameter: an array of values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The given array of numbers can ...
1) be empty 
2) contain only true values
3) contain only falsy values (like false, null, undefined)
4) contain a combination of both 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Returns&lt;/u&gt;&lt;br&gt;
The function should return one value: a number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The function should return 0 if ...
1) the array is empty
2) the array only contains falsy values
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The function should return a positive number if 
there is at least 1 sheep present (true) inside the array
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;br&gt;
&lt;em&gt;The test case in this challenge is the same as the example given in the instructions above.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;em&gt;See pseudo code section for each solution&lt;/em&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Solution 1: Using a for loop
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;This problem is fairly similar to the problem in kata 1 and will have a similar solution, except for a few minor tweaks.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Declare a 'count' variable.
2) Loop over the given array.
3) Check if the current value in the loop is TRUE.
4) If it is, add 1 to the current value of 'count'.
5) Return the 'count' variable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;JavaScript code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function countSheeps(arrayOfSheep) {
  let count = 0;
  for (let i = 0; i &amp;lt; arrayOfSheep.length; i++) {
    if (arrayOfSheep[i]) {
      count++;
    }
  }
  return count;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Notes&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;1) Often times, code newbies will write &lt;code&gt;if (condition === true)&lt;/code&gt;, which isn't inherently wrong, but is in fact unnecessary. In this case &lt;code&gt;arrayOfSheep[i]&lt;/code&gt; will evaluate to &lt;code&gt;true&lt;/code&gt; if the value is &lt;code&gt;true&lt;/code&gt; (or &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Truthy"&gt;truthy&lt;/a&gt;) and to &lt;code&gt;false&lt;/code&gt; if the value is &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Falsy"&gt;falsy&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;2) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Increment"&gt;increment operator (++)&lt;/a&gt; is used to add 1 to our counter of sheep present.&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 2: Using a forEach loop
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;The code from solution 1 can reduced to just 3 lines inside of the function using a forEach loop instead of a for loop and combining it with the conditional ternary operator seen in solution 3 of kata 1.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;JavaScript code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function countSheeps(arrayOfSheep) {
  let count = 0;
  arrayOfSheep.forEach(sheep =&amp;gt; sheep ? count++ : count);
  return count;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Notes&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;1) The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach"&gt;forEach loop&lt;/a&gt; executes the code specified in the callback function on each element in the array. &lt;/p&gt;

&lt;p&gt;2) Unlike the filter() and reduce() array methods, the forEach() array method returns &lt;code&gt;undefined&lt;/code&gt;, unless something is explicitly returned inside the callback function. &lt;/p&gt;

&lt;p&gt;3) The forEach loop is a great alternative to a for loop when looping over an array. It is less prone to off-by-one mistakes since it simply loops over every item in the array without us having to define the amount of times it should iterate like we do in a for loop.&lt;/p&gt;




&lt;h3&gt;
  
  
  Solution 3: Using the filter() array method and length property
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1) Create a new array containing only TRUE values.
2) Return the length of that array.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;JavaScript code&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function countSheeps(arrayOfSheep) {
  return arrayOfSheep.filter(sheep =&amp;gt; sheep).length;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Notes&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;1) Like kata 1, we use the filter() array method to create a new array, this time containing only the values of the sheep that are present in the array.&lt;/p&gt;

&lt;p&gt;2) Then we simply use the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length"&gt;length&lt;/a&gt; property to count the number of values in the newly created array.&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This is the solution I submitted for this kata. It is only 1 line of code, but is still easy to read and understand.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Kata 3: Keep up the hoop
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Instructions
&lt;/h3&gt;

&lt;p&gt;Alex just got a new hula hoop, he loves it but feels discouraged because his little brother is better than him.&lt;/p&gt;

&lt;p&gt;Write a program where Alex can input (n) how many times the hoop goes round and it will return him an encouraging message :)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If Alex gets 10 or more hoops, return the string "Great, now move on to tricks".&lt;/li&gt;
&lt;li&gt;If he doesn't get 10 hoops, return the string "Keep at it until you get it".&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Breaking down the problem with P.R.E.P.
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Parameters&lt;/u&gt;&lt;br&gt;
The function expects one parameter: a number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The number can be 0 or greater than 0, but should not be a
negative number.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Returns&lt;/u&gt;&lt;br&gt;
The function should return one value: a string (message).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The function should return "Great, now move on to tricks" if
the number is greater than or equal to 10.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The function should return "Keep at it until you get it" if
the number is smaller than 10.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;br&gt;
The following test cases are provided by CodeWars.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3 =&amp;gt; "Keep at it until you get it" 
11 =&amp;gt; "Great, now move on to tricks" 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Pseudo code&lt;/u&gt;&lt;br&gt;
&lt;em&gt;No pseudo code for this solution since it's been pretty much provided in the parameters and returns sections above.&lt;/em&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Solution 1: Using an if/else statement
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function hoopCount (n) {
  if (n &amp;gt;= 10) {
    return "Great, now move on to tricks";
  } else {
    return "Keep at it until you get it";
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Solution 2: Using a conditional ternary operator
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function hoopCount (n) {
  return n &amp;gt;= 10 
    ? "Great, now move on to tricks" 
    : "Keep at it until you get it";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;u&gt;Notes&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;It is not uncommon to see the code inside conditional ternary operators broken up into multiple lines like the code block above. This helps with legibility since the condition is one 1 line, followed by the code to be executed if it evaluates to true and lastly the code to be executed it evaluates to false.&lt;/p&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This is the solution I submitted for this challenge. I'm personally a big fan of ternary operators. I know some people find them hard to read, but for me, they're often easier to read then if/else statements (unless you have a lot of statements and/or they are nested).&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h3&gt;
  
  
  Solution 3: Adding error handlers
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;The first 2 solutions don't execute any code if the input given is invalid (a negative number or not a number at all). This was not a requirement to pass the test cases in the challenge, but a nice added extra.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function hoopCount (n) {
  if (n &amp;gt;= 10) {
    return "Great, now move on to tricks";
  } else if (n &amp;lt; 10 &amp;amp;&amp;amp; n &amp;gt;= 0) {
    return "Keep at it until you get it";
  } else {
    return "Invalid input"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;What solution did you implement?&lt;/strong&gt; &lt;br&gt;
&lt;strong&gt;What solution did you find the most elegant?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;What solution did you have trouble understanding?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let me know, I'd love to hear from you!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I hope you found this article helpful.&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;Connect with me on ...&lt;br&gt;
&lt;a href="https://twitter.com/Nat_A_Number"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/NatGeyzenTech"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>codewars</category>
      <category>challenge</category>
    </item>
    <item>
      <title>Becoming a JavaScript Code Warrior</title>
      <dc:creator>Nat's Tech Notes</dc:creator>
      <pubDate>Fri, 27 May 2022 20:46:54 +0000</pubDate>
      <link>https://dev.to/nats_tech_notes/becoming-a-javascript-code-warrior-f96</link>
      <guid>https://dev.to/nats_tech_notes/becoming-a-javascript-code-warrior-f96</guid>
      <description>&lt;p&gt;Today I'm starting my journey to becoming a JavaScript Code Warrior on &lt;a href="https://www.codewars.com/"&gt;CodeWars&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For the next 30 days I will be solving 3 coding challenges, or &lt;em&gt;kata&lt;/em&gt;, a day, as well as writing 3 possible solutions for each &lt;em&gt;kata&lt;/em&gt; solved. The first solution will be the simplest and most readable, followed by an intermediate one and ending with the most complex or advanced solution, which will often be a one-liner. It should go without saying, but all solutions will be written in JavaScript. &lt;/p&gt;

&lt;p&gt;Each day, I'll write a post discussing the &lt;em&gt;kata&lt;/em&gt; of the day where I break down the problems using the P.R.E.P. technique. P.R.E.P. stands for &lt;strong&gt;P&lt;/strong&gt;arameters, &lt;strong&gt;R&lt;/strong&gt;eturns, &lt;strong&gt;E&lt;/strong&gt;xamples and &lt;strong&gt;P&lt;/strong&gt;seudo Code and is an effective technique to use when solving coding challenges, especially for beginners who struggle with this. Of course I will also provide the 3 solutions mentioned above, with details on each of the implementations. &lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Important note:&lt;/strong&gt;&lt;br&gt;
I debated very heavily on the ethics of writing these posts, since I am aware they can be used for cheating purposes, which is against CodeWars' Code of Conduct - rightfully so. In fact, the Code of Conduct also discourages sharing solutions on GitHub, since it makes it easier for Code Warriors to look for a solution rather than putting in the work to complete the challenge themselves.&lt;/p&gt;

&lt;p&gt;However, while I understand their very valid concern, my posts will be focusing more on the process of solving the challenges and different approaches that can be taken, instead of just simply providing the solutions. These posts are for those of you that get stuck when trying to solve a challenge, have no idea how to go about breaking down the problem and/or are having issues understanding some of the (more complicated) alternative solutions that are provided after solving a challenge. &lt;/p&gt;

&lt;p&gt;That said, I do HIGHLY encourage you to try to solve/understand the challenge yourself first and if you get really stuck, these resources are here to help you get unstuck. &lt;/p&gt;




&lt;p&gt;Connect with me on ...&lt;br&gt;
&lt;a href="https://twitter.com/Nat_A_Number"&gt;Twitter&lt;/a&gt; &lt;br&gt;
&lt;a href="https://github.com/NatGeyzenTech"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>challenge</category>
      <category>webdev</category>
      <category>codewars</category>
    </item>
    <item>
      <title>How to become a Web Accessibility Specialist (WAS)</title>
      <dc:creator>Nat's Tech Notes</dc:creator>
      <pubDate>Tue, 01 Feb 2022 22:48:49 +0000</pubDate>
      <link>https://dev.to/nats_tech_notes/how-to-become-a-web-accessibility-specialist-was-19jp</link>
      <guid>https://dev.to/nats_tech_notes/how-to-become-a-web-accessibility-specialist-was-19jp</guid>
      <description>&lt;p&gt;If you're anything like me - and since you're here, I suspect you might be - you probably started with a good ol' Google Search. The first results that popped up were likely a bunch of organizations promising they can make your website fully compliant (oh those lovely ads).&lt;/p&gt;

&lt;p&gt;Now I'm not exactly looking to hire someone to make my website compliant - a.k.a. audit it. I want to become the person doing the audits myself. Again, since you're still reading this post, you presumably are as well. So how exactly do we become that person?&lt;/p&gt;

&lt;p&gt;First, we have to get certified - twice, at that. In this post, I will outline where to get certified, how much you can expect to pay for each certification, how to get started, and what steps to take next.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Where can I get certified?
&lt;/h2&gt;

&lt;p&gt;Certifications are obtained - and maintained - through IAAP, a.k.a. the International Association of Accessibility Professionals. So what exactly is the IAAP?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The International Association of Accessibility Professionals (IAAP) is a not-for-profit membership-based organization for individuals and organizations that are focused on accessibility or are in the process of building their accessibility skills and strategies. &lt;a href="https://www.accessibilityassociation.org/s/about"&gt;Information from IAAP's About page&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  2. First step
&lt;/h2&gt;

&lt;p&gt;Before being able to get certified as a WAS, the CPACC certification must be obtained first. IAAP's website describes it as follows:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The IAAP Certified Professional in Accessibility Core Competencies (CPACC) credential is IAAP's foundational certification, representing broad, cross-disciplinary conceptual knowledge about 1) disabilities, 2) accessibility and universal design, and 3) accessibility-related standards, laws, and management strategies. &lt;a href="https://www.accessibilityassociation.org/s/certified-professional"&gt;IAAP CPACC Certification Page&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As the description states, it addresses very broad and foundational knowledge about accessibility in general. It does include some aspects related directly to web accessibility, but only a very small percentage. The rest of it is focused on disabilities, adaptive strategies, and laws and regulations. It approaches all those topics from a legal, social, psychological, and economic perspective - and is therefore much more theoretical than practical.&lt;/p&gt;

&lt;p&gt;At the time of writing - though this might change - the price for this exam is $385 for members of IAAP and $485 for non-members. Membership prices will vary depending on the type of membership but can be found &lt;a href="https://www.accessibilityassociation.org/s/membership"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  3. What's next?
&lt;/h2&gt;

&lt;p&gt;Once the CPACC certification has been obtained, the time comes to get certified as a WAS. IAAP's website describes it as follows:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Technical-level credential is intended for accessibility professionals who are expected to evaluate the accessibility of existing content or objects according to published technical standards and guidelines, and provide detailed remediation recommendations. They are expected to know and use the relevant technologies, not merely be aware of them. &lt;a href="https://www.accessibilityassociation.org/s/wascertification"&gt;IAAP WAS Certification Page&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This certification, unlike the first one, is on a much more technical and practical level. It requires knowledge of HTML, JavaScript, usability testing in different environments, understanding of WCAG 2.1 standards, accessibility best practices, and more. While being able to write code yourself isn't exactly necessary, knowledge and understanding of web languages, however, are required.&lt;/p&gt;

&lt;p&gt;The price for this exam is $430 for members of IAAP and $530 for non-members at the time of writing - though, again, this might have changed by the time of reading. It should also be mentioned that people retaking the test - of either certification - do not pay this full price. All price information can be found on &lt;br&gt;
&lt;a href="https://www.accessibilityassociation.org/s/exam-pricing-discounts-and-payments0"&gt;this page&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Important things to note
&lt;/h2&gt;

&lt;h3&gt;
  
  
  4.1 Getting ready for the exam
&lt;/h3&gt;

&lt;p&gt;There is a whole process to obtaining each certification. From preparing and applying for it, paying and scheduling the exam, to taking it and waiting for the results - that luckily are fairly similar for both. &lt;/p&gt;

&lt;p&gt;I will be outlining these aspects in its own post that will be part of the series 'The road to becoming a WAS'. If it has already been written by the time you are reading this, you should be able to find it at the top of this post as part of that series - and I'll be adding another link here for your convenience. If neither of those are available, it means it has not been written YET (though you can follow me to get notified when it gets posted if you are interested in reading it).&lt;/p&gt;

&lt;h3&gt;
  
  
  4.2 Maintaining your certifications
&lt;/h3&gt;

&lt;p&gt;IAAP Certifications are valid for 3 years - to ensure that certified professionals keep up with fast-changing technologies, standards, and best practices. After that, they must be maintained - which is a separate procedure (that I won't be writing about right now, though I probably will when the times comes for me to renew mine).&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>inclusion</category>
      <category>career</category>
      <category>webdev</category>
    </item>
    <item>
      <title>From Former Special Ed Teacher To Future Web Accessibility Specialist</title>
      <dc:creator>Nat's Tech Notes</dc:creator>
      <pubDate>Fri, 28 Jan 2022 20:42:18 +0000</pubDate>
      <link>https://dev.to/nats_tech_notes/from-former-special-ed-teacher-to-future-web-accessibility-specialist-8m9</link>
      <guid>https://dev.to/nats_tech_notes/from-former-special-ed-teacher-to-future-web-accessibility-specialist-8m9</guid>
      <description>&lt;h2&gt;
  
  
  Chapter 1: Becoming a teacher
&lt;/h2&gt;

&lt;p&gt;Like most people's lives, mine has been a mix of free will and pure happenstance. For example, it was my choice to get a degree in education, because I wanted to make a positive difference in this world. So much so, that I chose (world) religion as one of the two specifications within the general curriculum. I wanted - and did - teach some of the future contributors to our society about the differences between people, cultures, and religions. I dare even say that for most, I managed to help them understand and accept those differences, instead of fearing them, and assisted them in seeing the beauty in all of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Chapter 2: Learning from special education
&lt;/h2&gt;

&lt;p&gt;It was fate, however, that nudged me into the direction of special education. While my degree's curriculum did include some introductory and pretty surface-level classes related to disabilities - mostly, but not exclusively, cognitive and learning disabilities - I had honestly never considered that route.&lt;/p&gt;

&lt;p&gt;That is until I started applying for jobs after graduation and ended up getting only one reply out of many applications. It happened to be a position for both of the specifications I had chosen (the second being English as a Second Language - which has also served me incredibly well in many different ways). I went on the interview and about an hour after, I got the phone call saying they wanted to offer me the job. With no other options on the table for me, I accepted, and let me tell you; it was the best thing that could have happened to me. That was what first opened my eyes to how disabilities affect a person's life in so many different ways.&lt;/p&gt;

&lt;p&gt;I ended up teaching teenagers with autism and got training from the school itself before I ever started the job. It was there that I learned that simple things that are so often overlooked, like what fonts are used, can significantly improve or decrease a neurodivergent person's chance of being able to process information. Or how to structure text and content in a way that isn't overcrowded and convoluted, a mistake that unfortunately is made so frequently.&lt;/p&gt;

&lt;p&gt;All small, but important techniques, that taught me so incredibly much about styling, structuring, and organizing content in an inclusive way. Skills that, unbeknownst to me at the time, would be extremely valuable once I transitioned into programming.&lt;/p&gt;

&lt;p&gt;Now my main focus was mostly neurodiversity and adaptive strategies for learning disabilities such as dyslexia for example. The school I was working for, however, did also have students that were hard of hearing or deaf and ones with low vision or blindness. I obviously did not have the proper experience to properly support students with those needs, but it did also give me a glimpse into some of the adaptive strategies they needed to be able to read, learn and process information.&lt;/p&gt;

&lt;h2&gt;
  
  
  Chapter 3: Switching to programming
&lt;/h2&gt;

&lt;p&gt;Unfortunately, while I absolutely loved teaching, there were a few reasons I ultimately decided to step out of that sector. Not long after that I made a huge life change and ended up moving halfway across the world - to a country that did not even acknowledge my teaching degree as equal to theirs. So that left me with the question: what do I do now?&lt;/p&gt;

&lt;p&gt;In another twist of kismet, I was obsessed with the tv show Silicon Valley at the time, especially the coding aspect of it. To the point where I started looking for other coding-related shows and movies that I could watch (though I never did quite find any I enjoyed as much). It was then that I had the not completely random thought that I could see myself potentially being a programmer.&lt;/p&gt;

&lt;p&gt;Not one to let a possible opportunity go to waste, I sat down at my computer and started looking up how to start my coding journey. Like many others, I didn't have any specific path in mind. I wasn't sure if I wanted to go into gaming, software, web development, or any of the other routes that can be taken in programming. I just figured I would try coding and see if I liked it and if I didn't, well, no harm no foul.&lt;/p&gt;

&lt;h2&gt;
  
  
  Chapter 4: Code Newbie
&lt;/h2&gt;

&lt;p&gt;Given that I didn't have a specific programming direction in mind, I decided to go about it a little differently. There were a couple of websites that mentioned that if you grasped C++, any other programming language would be much easier to learn. Of course, that settled it for me - cause why take the easy road when the hard road is so much more fun.&lt;/p&gt;

&lt;p&gt;I will admit, I quite liked learning C++, right up until those dreaded pointers came up and I got completely lost. Before that though, I was pretty surprised by how much fun I was having. Given that the first program I ever wrote was a complete mock-up of a reset password process - with security questions and a 3 limit attempt and all - to practice concepts like loops and conditional statements, I clearly had a natural knack for it as well. Can't say I haven't surprised a ton of people when I tell them that was my first written program either!&lt;/p&gt;

&lt;p&gt;Deciding C++ might not be the right fit for me though, I ultimately landed on web development and from there, everything naturally fell into place. I started learning HTML, moved on to CSS, then JavaScript - with lots of swearing and feeling dumb at times - followed by React and dipping my toes into the back-end with NodeJS and MongoDB. I especially took an interest in concepts like semantic HTML and accessibility, understanding the importance of them from my particular experiences and background.&lt;/p&gt;

&lt;h2&gt;
  
  
  Chapter 5: Tying it all together
&lt;/h2&gt;

&lt;p&gt;It wasn't until recently that it dawned on me: I should become a Web Accessibility Specialist. Now granted, like most code newbies, it took me a while to feel confident in my own skills - we all know how real Imposter Syndrome is. It hasn't even really been that long since I stopped referring to myself as a code newbie in all honesty.&lt;/p&gt;

&lt;p&gt;There comes a time in our journey, however, that a shift occurs, an ascension, if you will. I stopped feeling like I was still simply learning - though let's be honest, that's a never-ending process in programming - and started feeling like I knew what I was doing and what I was talking about. It was then that I gained the confidence to let the last pieces of the puzzle fall into place and to embark on the next phase of my journey: obtaining the required certifications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Chapter 6: Sharing is caring
&lt;/h2&gt;

&lt;p&gt;Not only am I incredibly excited to learn and expand my knowledge of the subject, but I am also thrilled to be using this platform as a way to document the process of obtaining the certifications. As I go through the body of knowledge for each exam, I will be writing posts - study notes, if you will - about the different categories and concepts that one should know to pass the exams.&lt;/p&gt;

&lt;p&gt;If I can help out other people on the same journey as me, especially, but not exclusively, people that might be struggling with some of the (more theoretical) aspects, that would just be the cherry on top of the pie. Maybe I might even inspire some folks out there to start this journey themselves. After all, the more people become knowledgeable about web accessibility, the better for the future of the web - and all the people out there that are currently being excluded from a big part of it.&lt;/p&gt;

</description>
      <category>inclusion</category>
      <category>webdev</category>
      <category>leadership</category>
      <category>writing</category>
    </item>
  </channel>
</rss>
