Skip to content

Instantly share code, notes, and snippets.

@iceener
Created December 24, 2020 19:58
Show Gist options
  • Save iceener/e4c3da4db91ec16930b34956a8678a10 to your computer and use it in GitHub Desktop.
Save iceener/e4c3da4db91ec16930b34956a8678a10 to your computer and use it in GitHub Desktop.
function christmas(x) {
if(x < 3) {
return "";
}
let tree = "";
for(let i = 1; i <= x; i++) {
for(let j = 1; j <= x + x - 1; j++) {
if(j <= x - i || j >= x + i) {
tree += " ";
} else {
tree += "*";
}
}
tree += "\n";
}
return tree;
}
console.log(christmas(10));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment