Skip to content

Instantly share code, notes, and snippets.

@elevenpassin
Created October 25, 2017 17:25
Show Gist options
  • Save elevenpassin/2aa3818fce15ef1e5e75c70ffc8bd239 to your computer and use it in GitHub Desktop.
Save elevenpassin/2aa3818fce15ef1e5e75c70ffc8bd239 to your computer and use it in GitHub Desktop.
/*
A pretty simple pyramid class that can be used to create a pyramid.
Methods in the class can be used to print out the pyramid in different ways.
*/
class Pyramid{
constructor(sizeOfPyramid){
this.size = sizeOfPyramid;
}
printLeftAligned(){
for (var i = 0; i < this.size; i++){
let newline = '';
for (var j = 0; j < i; j++){
newline+= "#";
}
console.log(newline);
}
}
printRightAligned(){
for (var i = 0; i < this.size ; i++){
let newline = '';
for (var j = 0; j < (this.size - i); j++){
newline += " ";
}
for (var k = 0; k < i; k++){
newline += "#";
}
console.log(newline);
}
}
}
// const pyr = new Pyramid(10);
// pyr.printLeftAligned();
// pyr.printRightAligned();
module.exports = {
Pyramid : Pyramid
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment