Skip to content

Instantly share code, notes, and snippets.

@MohamedGamil
Created April 17, 2022 06:11
Show Gist options
  • Save MohamedGamil/1ea33ea78d4cb3e4b280d6f596fc5ec0 to your computer and use it in GitHub Desktop.
Save MohamedGamil/1ea33ea78d4cb3e4b280d6f596fc5ec0 to your computer and use it in GitHub Desktop.
HackerRank / Staircase
'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