Skip to content

Commit a09ec3c

Browse files
committed
♻️ refactor solution for challenge 7
1 parent 623e922 commit a09ec3c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/challenges/07.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
export function drawGift (size: number, symbol: string): string {
22
const topLines = []
33
const bottomLines = []
4+
const symbolPattern = symbol.repeat(Math.max(0, size - 2))
45
for (let i = 0; i < size - 1; ++i) {
56
let line = ''
67
if (i === 0) {
78
line = '#'.repeat(size)
89
} else {
9-
line = `#${symbol.repeat(Math.max(0, size - 2))}#${symbol.repeat(i - 1)}#`
10+
const symPtn = symbol.repeat(i - 1)
11+
line = `#${symbolPattern}#${symPtn}#`
1012
}
1113
const spaces = size - i - 1
1214
topLines.push(`${' '.repeat(spaces)}${line}`)
1315
bottomLines.unshift(line)
1416
}
15-
// console.log(topLines)
16-
// console.log(bottomLines)
17-
const middleLine = size > 1 ? `\n${'#'.repeat(size)}${symbol.repeat(Math.max(0, size - 2))}#\n` : '#'
17+
const barrer = '#'.repeat(size)
18+
const middleLine = size > 1
19+
? `\n${barrer}${symbolPattern}#\n`
20+
: '#'
1821
const result = topLines.join('\n') + middleLine + bottomLines.join('\n')
1922
return result + '\n'
2023
}

0 commit comments

Comments
 (0)