Skip to content

Instantly share code, notes, and snippets.

@aksnell
Created July 7, 2020 14:13
Show Gist options
  • Save aksnell/53e2afc1a60113e662d97b7911cd299d to your computer and use it in GitHub Desktop.
Save aksnell/53e2afc1a60113e662d97b7911cd299d to your computer and use it in GitHub Desktop.
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