Created
September 8, 2015 22:02
-
-
Save jluismm2311/ddb3c6ed0c2109e0e8f5 to your computer and use it in GitHub Desktop.
Create a function christmasTree(height) that returns a christmas tree of the correct height christmasTree(5) should return: * *** ***** ******* ********* Height passed is always an integer between 0 and 100. Use \n for newlines between each line. Pad with spaces so each line is the same length. The last line having only stars, no spaces.
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
function christmasTree(height) { | |
var value = ""; | |
for(i = 1; i<= height; i++ ) { | |
var blank = " ".repeat(height-i); | |
value += blank + "*".repeat(1+((i-1)*2)) + blank; | |
value += i < height ? "\n" : ""; | |
} | |
return value | |
} | |
String.prototype.repeat = function(times) { | |
return (new Array(times + 1)).join(this); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment