Skip to content

Instantly share code, notes, and snippets.

@lasverg
Created April 7, 2018 08:29
Show Gist options
  • Save lasverg/85c26b77fb409e5071304c6c8fd43f6d to your computer and use it in GitHub Desktop.
Save lasverg/85c26b77fb409e5071304c6c8fd43f6d to your computer and use it in GitHub Desktop.
Staircase | Solution | JavaScript
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