-
Notifications
You must be signed in to change notification settings - Fork 1
/
challenge-18.ts
48 lines (40 loc) · 1.21 KB
/
challenge-18.ts
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
42
43
44
45
46
47
48
export function drawClock(time: string) {
const clock: string[][] = [[], [], [], [], [], [], []]
const full = ['*', '*', '*']
const open = ['*', ' ', '*']
const start = ['*', ' ', ' ']
const end = [' ', ' ', '*']
const spaces = [' ', ' ', ' ']
const middle = [' ', '*', ' ']
const numbers: Record<string, string[][]> = {
0: [full, open, open, open, open, open, full],
1: [end, end, end, end, end, end, end],
2: [full, end, end, full, start, start, full],
3: [full, end, end, full, end, end, full],
4: [open, open, open, full, end, end, end],
5: [full, start, start, full, end, end, full],
6: [full, start, start, full, open, open, full],
7: [full, end, end, end, end, end, end],
8: [full, open, open, full, open, open, full],
9: [full, open, open, full, end, end, full],
}
const colon = [spaces, spaces, middle, spaces, middle, spaces, spaces]
const one = numbers[time[0]]
const two = numbers[time[1]]
const four = numbers[time[3]]
const five = numbers[time[4]]
let i = 0
for (const item of clock) {
item.push(
...one[i],
' ',
...two[i],
...colon[i],
...four[i],
' ',
...five[i],
)
i++
}
return clock
}