Created
April 17, 2022 06:11
-
-
Save MohamedGamil/1ea33ea78d4cb3e4b280d6f596fc5ec0 to your computer and use it in GitHub Desktop.
HackerRank / Staircase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf-8'); | |
let inputString = ''; | |
let currentLine = 0; | |
process.stdin.on('data', function(inputStdin) { | |
inputString += inputStdin; | |
}); | |
process.stdin.on('end', function() { | |
inputString = inputString.split('\n'); | |
main(); | |
}); | |
function readLine() { | |
return inputString[currentLine++]; | |
} | |
/* | |
* Complete the 'staircase' function below. | |
* | |
* The function accepts INTEGER n as parameter. | |
*/ | |
function staircase(n) { | |
let remaining = 1; | |
for (let idx = 0; idx < n; idx++) { | |
const spaces = (" ").repeat(n - remaining); | |
const hashes = ("#").repeat(remaining++); | |
const str = spaces + hashes; | |
console.log(str); | |
} | |
} | |
function main() { | |
const n = parseInt(readLine().trim(), 10); | |
staircase(n); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment