-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsolution.js
37 lines (31 loc) · 872 Bytes
/
solution.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function drawGift(size, symbol) {
const result = [];
function createLine(spacesBefore, content) {
result.push(" ".repeat(spacesBefore) + content);
}
createLine(size - 1, "#".repeat(size));
for (let i = 0; i < size - 2; i++) {
const spaces = size - 2 - i;
const inner =
" ".repeat(spaces) +
"#" +
symbol.repeat(size - 2) +
"#" +
symbol.repeat(i) +
"#";
createLine(0, inner);
}
if (size > 1) {
const mid = "#".repeat(size) + symbol.repeat(size - 2) + "#";
createLine(0, mid);
for (let i = 0; i < size - 2; i++) {
const inner =
"#" + symbol.repeat(size - 2) + "#" + symbol.repeat(size - 3 - i) + "#";
createLine(0, inner);
}
}
if (size - 2 >= 0)
createLine(0, [..."#".repeat(size)].reverse().join("").trim());
result.push("");
return result.join("\n");
}