Created
October 25, 2017 17:25
-
-
Save elevenpassin/2aa3818fce15ef1e5e75c70ffc8bd239 to your computer and use it in GitHub Desktop.
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
/* | |
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