-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawGift.js
32 lines (24 loc) · 884 Bytes
/
drawGift.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
export function drawGift(size, symbol) {
const symbolLine = '#'
let result = ''
let bodyTop = ''
let bodyBottom = ''
let mitad = size - 2
mitad += +!(mitad + 1)
for (let i = 0; i < mitad; i++) {
let line = symbolLine + symbol.repeat(mitad) + symbolLine + symbol.repeat(i) + symbolLine
bodyTop += ' '.repeat(mitad - i) + line + '\n'
bodyBottom = line + '\n' + bodyBottom
}
const boxMitad = symbolLine.repeat(size) + symbol.repeat(mitad) + symbolLine + '\n'
const lineStart = ' '.repeat(size - 1) + symbolLine.repeat(size) + '\n'
const lineEnd = symbolLine.repeat(size) + '\n'
result = lineStart + (bodyTop + boxMitad + bodyBottom + lineEnd).repeat(+!!(size - 1))
return result
}
const result = drawGift(4, '+')
console.log(result)
const result2 = drawGift(5, '*')
console.log(result2)
const result3 = drawGift(1, '^')
console.log(result3)