Created
May 20, 2016 00:40
-
-
Save deltamualpha/941e826e0023a961fb4426eba0986665 to your computer and use it in GitHub Desktop.
another coding challenge that came up recently: given an odd number, return a centered pyramid with a base that width.
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
var pyramid = function(width) { | |
if (width % 2 == 0) { | |
console.log("odd numbers only, please"); | |
return; | |
} | |
var gaps = ''; | |
for (var i = ((width-1)/2); i >= 0; i--) { | |
gaps += ' '; | |
} | |
var hashes = '#'; | |
while(gaps.length > 0) { | |
gaps = gaps.substring(0, gaps.length - 1); | |
console.log(gaps + hashes); | |
hashes += "##"; | |
} | |
} | |
pyramid(process.argv[2]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think I know where this one might come from.