AbrahamJLR | function createXmasTree(height, ornament) {
let tree = "";
const underscores = "_".repeat(height);
const ornaments = ornament.repeat(height * 2 - 1);
for (let i = 1; i <= height; i++) {
const padding = underscores.slice(0, height - i);
const ornamentsLine = ornaments.slice(0, i * 2 - 1);
tree += padding + ornamentsLine + padding + "\n";
}
const trunk = underscores.slice(0, height - 1) + "#" + underscores.slice(0, height - 1);
tree += trunk + "\n" + trunk;
return tree;
}
const tree1 = createXmasTree(5, '*')
const tree2 = createXmasTree(3, '+')
const tree3 = createXmasTree(6, '@')
const tree4 = createXmasTree(200, '*')
const tree5 = createXmasTree(4000, '+')
| ready |
Sundac | function createXmasTree(height, ornament) {
let tree = "";
let _ = "_".repeat(height - 1);
for (let i = 1; i <= height; i++) {
const padding = _.slice(0, height - i);
const leaves = ornament.repeat(i * 2 - 1);
tree += `${padding}${leaves}${padding}\n`;
}
tree += `${_}#${_}\n${_}#${_}`;
return tree;
}
const tree1 = createXmasTree(5, '*')
const tree2 = createXmasTree(3, '+')
const tree3 = createXmasTree(6, '@')
const tree4 = createXmasTree(200, '*')
const tree5 = createXmasTree(4000, '+')
| ready |