Created
August 28, 2018 12:51
-
-
Save ronit-mukherjee/e0d791283ae8b3fc8b1e0d855105b23b to your computer and use it in GitHub Desktop.
HackerRank - Right Aligned Triangle (JS)
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
//https://www.hackerrank.com/challenges/staircase/problem | |
'use strict'; | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf-8'); | |
let inputString = ''; | |
let currentLine = 0; | |
process.stdin.on('data', inputStdin => { | |
inputString += inputStdin; | |
}); | |
process.stdin.on('end', _ => { | |
inputString = inputString.replace(/\s*$/, '') | |
.split('\n') | |
.map(str => str.replace(/\s*$/, '')); | |
main(); | |
}); | |
function readLine() { | |
return inputString[currentLine++]; | |
} | |
// Complete the staircase function below. | |
function staircase(n) { | |
let staircase = ""; | |
for(let r=0;r<n;r++){ | |
for(let c = 0; c<n; c++){ | |
if(c<(n-1)-r){ | |
staircase += " "; | |
} else{ | |
staircase += "#"; | |
} | |
} | |
staircase += "\n"; | |
} | |
console.log(staircase); | |
} | |
function main() { | |
const n = parseInt(readLine(), 10); | |
staircase(n); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment