Person::new("Nat"); | function createXmasTree(height, ornament) {
return Array.from({length: height}, (_, j) => '_'.repeat(height - 1 - j) + ornament.repeat(j * 2 + 1) + '_'.repeat(height - 1 - j)).join('\n') + '\n' + '_'.repeat(height - 1) + '#' + '_'.repeat(height - 1) + '\n' + '_'.repeat(height - 1) + '#' + '_'.repeat(height - 1);
}
const tree1 = createXmasTree(5, '*')
const tree2 = createXmasTree(3, '+')
const tree3 = createXmasTree(6, '@')
const tree4 = createXmasTree(200, '*')
const tree5 = createXmasTree(4000, '+')
| ready |
AbrahamJLR | function createXmasTree(height, ornament) {
let tree = "";
let _ = "_".repeat(~-height);
for (let i = 1; i <= height; i++) {
const padding = _.slice(0, height - i);
tree += padding+ornament.repeat(~-(i * 2))+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 |
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 |