Skip to content

Instantly share code, notes, and snippets.

@jonfriesen
Last active June 11, 2016 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonfriesen/7129869fe3e4311f44bc057ccbaa1a37 to your computer and use it in GitHub Desktop.
Save jonfriesen/7129869fe3e4311f44bc057ccbaa1a37 to your computer and use it in GitHub Desktop.
Create a set of stairs using hashes
// 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