<?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: Christotle Agholor</title>
    <description>The latest articles on DEV Community by Christotle Agholor (@johnchristotle).</description>
    <link>https://dev.to/johnchristotle</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%2F953947%2Fef0d1b43-436f-449f-ab96-01a9fe85a8c7.jpeg</url>
      <title>DEV Community: Christotle Agholor</title>
      <link>https://dev.to/johnchristotle</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/johnchristotle"/>
    <language>en</language>
    <item>
      <title>StairCase | HackerRank Solution in JavaScript</title>
      <dc:creator>Christotle Agholor</dc:creator>
      <pubDate>Tue, 25 Oct 2022 19:48:45 +0000</pubDate>
      <link>https://dev.to/johnchristotle/staircase-hackerrank-solution-in-javascript-4mm1</link>
      <guid>https://dev.to/johnchristotle/staircase-hackerrank-solution-in-javascript-4mm1</guid>
      <description>&lt;p&gt;Let's look at the Problem Statement :&lt;/p&gt;

&lt;p&gt;Input Format&lt;br&gt;
A single integer, n, denoting the size of the staircase.&lt;/p&gt;

&lt;p&gt;Constraints: 0 &amp;lt; n &amp;lt;= 100&lt;/p&gt;

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

&lt;p&gt;Print a staircase of size using # symbols and spaces.&lt;/p&gt;

&lt;p&gt;Note: The last line must have spaces in it.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
Sample Input : 4&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   #
  ##
 ###
####
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Solution 1. in JavaScript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function staircase(n) {
    // Write your code here
    let str = '';
    for(let i = 1; i &amp;lt; n + 1; i++) {
        str += Array(n - i).fill(' ').join('')
        str += Array(i).fill('#').join('')
        console.log(str)
        str = ''
    }

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

&lt;/div&gt;



&lt;p&gt;Solution 2. in JavaScript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function staircase(n) {
  for (let i = 0; i &amp;lt; n; i++) {
    let str = Array(i + 1)
      .fill("#")
      .join("")
      .padStart(n);
    console.log(str);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OR&lt;/p&gt;

&lt;p&gt;// without the padStart it will still give same result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function staircase(n) {
  for (let i = 0; i &amp;lt; n; i++) {
    let str = Array(i + 1)
      .fill("#")
      .join("")
     console.log(str);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but in this case, the element flows to the left&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#
##
###
####
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>hackerrank</category>
      <category>solution</category>
      <category>staircase</category>
    </item>
  </channel>
</rss>
