Created
December 22, 2017 21:50
-
-
Save farskid/ab54f1813b2b5e5bcfb3f6ee6000ba23 to your computer and use it in GitHub Desktop.
Javascript draw stairs by number
This file contains hidden or 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 draw(n) { | |
var steps = new Array(n).fill('#'); | |
var len = steps.length; | |
steps = steps.map((val, i) => { | |
return new Array(len - i - 1).fill(' ').join('') + val + new Array(i).fill('#').join(''); | |
}); | |
return steps.join('\n'); | |
} | |
/* | |
draw(6); | |
# | |
## | |
### | |
#### | |
##### | |
###### | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment