-
Notifications
You must be signed in to change notification settings - Fork 0
/
07.js
41 lines (36 loc) · 883 Bytes
/
07.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
38
39
40
41
function drawGift(size, symbol) {
let cube = [];
let space = " ";
let borderSymbol = "#";
let bgSymbol = symbol.toString();
let width = size - 2;
let i = 1;
while (i <= size) {
let newline = "";
newline += space.repeat(size - i);
if (i === 1) {
newline += borderSymbol.repeat(size);
} else if (i === size) {
newline +=
borderSymbol.repeat(size) + bgSymbol.repeat(width) + borderSymbol;
} else {
newline +=
borderSymbol +
bgSymbol.repeat(width) +
borderSymbol +
bgSymbol.repeat(i - 2) +
borderSymbol;
}
newline += "\n";
cube.push(newline);
i++;
}
let j = width;
while (j >= 0) {
let newline = cube[j].trim() + "\n";
cube.push(newline);
j--;
}
const stringCube = cube.join("");
return stringCube;
}