Skip to content

Instantly share code, notes, and snippets.

@deltamualpha
Created May 20, 2016 00:40
Show Gist options
  • Save deltamualpha/941e826e0023a961fb4426eba0986665 to your computer and use it in GitHub Desktop.
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.
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]);
@misteroneill
Copy link

I think I know where this one might come from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment