Created
April 7, 2018 08:29
-
-
Save lasverg/85c26b77fb409e5071304c6c8fd43f6d to your computer and use it in GitHub Desktop.
Staircase | Solution | JavaScript
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
function staircase(n) { | |
// Two dimensional array concept | |
for(let i = 0; i < n; i++){ | |
// Clear the output after each loop | |
let output = ''; | |
for(let j = 0; j < n; j++){ | |
// Loop through, whenever (n-1-i) is bigger than j concat a space else # | |
j < (n -1 -i) ? output += ' ': output += '#'; | |
} | |
console.log(output); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment