Last active
June 11, 2016 23:12
-
-
Save jonfriesen/7129869fe3e4311f44bc057ccbaa1a37 to your computer and use it in GitHub Desktop.
Create a set of stairs using hashes
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
// Build a function that draws a set of stairs using hashes | |
// that climb vertically from left to right. The bottom stairs | |
// should have no spaces in front of it, for example: | |
// This is a set of 3 | |
// # | |
// ## | |
//### | |
function hashStairs(num, spaces, notFirstRun) { | |
if (!num || num <= 0) { return ''; } | |
if (!spaces) { spaces = ''; }; | |
if (!!notFirstRun) { spaces += ' '; } | |
notFirstRun = true; | |
var hashString = hashStairs(num - 1, spaces, notFirstRun) + '#'; | |
console.log(spaces + hashString); | |
return hashString; | |
}; | |
console.log('Draw Stairs'); | |
hashStairs(5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment