File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 1
1
export function drawGift ( size : number , symbol : string ) : string {
2
2
const topLines = [ ]
3
3
const bottomLines = [ ]
4
+ const symbolPattern = symbol . repeat ( Math . max ( 0 , size - 2 ) )
4
5
for ( let i = 0 ; i < size - 1 ; ++ i ) {
5
6
let line = ''
6
7
if ( i === 0 ) {
7
8
line = '#' . repeat ( size )
8
9
} 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 } #`
10
12
}
11
13
const spaces = size - i - 1
12
14
topLines . push ( `${ ' ' . repeat ( spaces ) } ${ line } ` )
13
15
bottomLines . unshift ( line )
14
16
}
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
+ : '#'
18
21
const result = topLines . join ( '\n' ) + middleLine + bottomLines . join ( '\n' )
19
22
return result + '\n'
20
23
}
You can’t perform that action at this time.
0 commit comments