Skip to content

Instantly share code, notes, and snippets.

@thehypergraph
Created December 29, 2024 10:03
Show Gist options
  • Save thehypergraph/d4819440be692b66c2075d9327116535 to your computer and use it in GitHub Desktop.
Save thehypergraph/d4819440be692b66c2075d9327116535 to your computer and use it in GitHub Desktop.
Christmas Tree
function christmasTree(w: number, ch: string, sep: string, isEmoji: boolean = false) {
if (w % 2 !== 0) {
console.log('Please pick an even number for the height of the tree.')
return
}
const spacingMultiplier = isEmoji ? 2 : 1 // Emoji characters are roughly 2 spaces wide
for (let i = 1; i < w; i += 2) {
const spacing = (w - i - 1) / 2
const side = sep.repeat(spacing * spacingMultiplier)
const row = side + ch.repeat(i) + side
console.log(row)
}
}
// For emoji with space separator, set isEmoji to true
// christmasTree(20, '🎄', ' ', true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment