<?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: Last_Samurai 🇧🇼🇿🇦</title>
    <description>The latest articles on DEV Community by Last_Samurai 🇧🇼🇿🇦 (@mr_odore).</description>
    <link>https://dev.to/mr_odore</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%2F160185%2Fdb674f0b-b2f2-4461-ad2e-fae83a4989ee.jpg</url>
      <title>DEV Community: Last_Samurai 🇧🇼🇿🇦</title>
      <link>https://dev.to/mr_odore</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mr_odore"/>
    <language>en</language>
    <item>
      <title>How to Create a Database in MongoDB</title>
      <dc:creator>Last_Samurai 🇧🇼🇿🇦</dc:creator>
      <pubDate>Mon, 31 Aug 2020 08:00:36 +0000</pubDate>
      <link>https://dev.to/mr_odore/how-to-create-a-database-in-mongodb-1edl</link>
      <guid>https://dev.to/mr_odore/how-to-create-a-database-in-mongodb-1edl</guid>
      <description>&lt;h2&gt;
  
  
  Creating a MongoDB Database with the CLI (the MongoDB shell)
&lt;/h2&gt;

&lt;p&gt;Open your terminal and type the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Thereafter,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;show dbs
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;What will be retrieved is admin and local, also note that these two instances are part of every cluster.&lt;/p&gt;

&lt;p&gt;Now let us create own! Take note that there is no create keyword. We are going to use 'use' instead.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use myAwesomeDB
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We are done. Now you need to insert your schema and data for it to reflect.&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>node</category>
    </item>
    <item>
      <title>Counting Valleys - Coding Challenge</title>
      <dc:creator>Last_Samurai 🇧🇼🇿🇦</dc:creator>
      <pubDate>Mon, 10 Aug 2020 07:15:36 +0000</pubDate>
      <link>https://dev.to/mr_odore/counting-valleys-coding-challenge-4j97</link>
      <guid>https://dev.to/mr_odore/counting-valleys-coding-challenge-4j97</guid>
      <description>&lt;p&gt;Gary is an avid hiker. He tracks his hikes meticulously, paying close attention to small details like topography. During his last hike he took exactly  steps. For every step he took, he noted if it was an uphill, , or a downhill,  step. Gary's hikes start and end at sea level and each step up or down represents a  unit change in altitude. We define the following terms:&lt;/p&gt;

&lt;p&gt;A mountain is a sequence of consecutive steps above sea level, starting with a step up from sea level and ending with a step down to sea level.&lt;br&gt;
A valley is a sequence of consecutive steps below sea level, starting with a step down from sea level and ending with a step up to sea level.&lt;br&gt;
Given Gary's sequence of up and down steps during his last hike, find and print the number of valleys he walked through.&lt;/p&gt;

&lt;p&gt;For example, if Gary's path is , he first enters a valley  units deep. Then he climbs out an up onto a mountain  units high. Finally, he returns to sea level and ends his hike.&lt;/p&gt;

&lt;p&gt;Function Description&lt;/p&gt;

&lt;p&gt;Complete the countingValleys function in the editor below. It must return an integer that denotes the number of valleys Gary traversed.&lt;/p&gt;

&lt;p&gt;countingValleys has the following parameter(s):&lt;/p&gt;

&lt;p&gt;n: the number of steps Gary takes&lt;br&gt;
s: a string describing his path&lt;br&gt;
Input Format&lt;/p&gt;

&lt;p&gt;The first line contains an integer , the number of steps in Gary's hike.&lt;br&gt;
The second line contains a single string , of  characters that describe his path.&lt;/p&gt;

&lt;p&gt;Constraints&lt;/p&gt;

&lt;p&gt;Output Format&lt;/p&gt;

&lt;p&gt;Print a single integer that denotes the number of valleys Gary walked through during his hike.&lt;/p&gt;

&lt;p&gt;Sample Input&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;8
UDDDUDUU 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Sample Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Explanation&lt;/p&gt;

&lt;p&gt;If we represent _ as sea level, a step up as /, and a step down as \, Gary's hike can be drawn as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_/\      _
   \    /
    \/\/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;He enters and leaves one valley.&lt;/p&gt;

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

&lt;p&gt;This is coding challenge labelled easy on &lt;a href="https://www.hackerrank.com/"&gt;Hacker rank&lt;/a&gt;  but it was not so easy for me. It took me about 45 minutes to solve, thus easy is relative term.&lt;/p&gt;

&lt;p&gt;In order to solve the problem we have to take into consideration what is asked of us, that is we are only interested in counting the number of valleys. From the sample above if you convert the U to +1 and D to -1, the sum will be 0, and of the U and D, we end the stream at U. So you can conclude from that pattern that a valley is constituted by U &amp;amp; D summing up to 0 and the last char in the string being equal to U. We can represent this algorithm by code as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function countingValleys(n, s) {
    let level = 0;
    let valley = 0;
    s.split('').forEach(item =&amp;gt; {
        if (item === 'U') {
            ++level;
        } else{
            --level;
        }
        if (item === 'U' &amp;amp;&amp;amp; level === 0) {
            ++valley;
        }
    });

    return valley;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Full Solution
&lt;/h3&gt;

&lt;p&gt;Below is the full solution which you can run in node js.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use strict';

const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin =&amp;gt; {
    inputString += inputStdin;
});

process.stdin.on('end', _ =&amp;gt; {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str =&amp;gt; str.replace(/\s*$/, ''));

    main();
});

function readLine() {
    return inputString[currentLine++];
}

// Complete the countingValleys function below.
function countingValleys(n, s) {
    let lvl = 0;
    let v = 0;
    s.split('').forEach(item =&amp;gt; {
        if (item === 'U') {
            ++lvl;
        } else{
            --lvl;
        }
        if (item === 'U' &amp;amp;&amp;amp; lvl === 0) {
            ++v;
        }
    });

    return v;
}

function main() {
    const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

    const n = parseInt(readLine(), 10);

    const s = readLine();

    let result = countingValleys(n, s);

    ws.write(result + "\n");

    ws.end();
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Thank you for reading my first ever article. &lt;/p&gt;

&lt;p&gt;My name is &lt;a href="https://github.com/MrObonye"&gt;Letlhogonolo Theodore Obonye&lt;/a&gt;&lt;br&gt;
I'm a JavaScript developer&lt;/p&gt;

</description>
      <category>codingchallenge</category>
      <category>node</category>
      <category>interviewprep</category>
    </item>
  </channel>
</rss>
