Created
July 7, 2020 14:13
-
-
Save aksnell/53e2afc1a60113e662d97b7911cd299d to your computer and use it in GitHub Desktop.
This file contains hidden or 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) { | |
if (height === 0) return '' | |
const tree = ['*'.repeat((height*2)-1)] | |
for (let i = 0; i < height - 1; i++) { | |
tree.push(tree[i].replace(/(\*)(?=\s|$)|(?<=\s|^)(\*)/g, ' ')) | |
} | |
return tree.reverse().join('\n') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment