forked from VladimirIvanov93/javascript-tasks-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
roman-time.js
104 lines (94 loc) · 2.08 KB
/
roman-time.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
var lower = {
0: '',
1: 'I',
2: 'II',
3: 'III',
4: 'IV',
5: 'V',
6: 'VI',
7: 'VII',
8: 'VIII',
9: 'IX'
};
var higher = {
0: '',
1: 'X',
2: 'XX',
3: 'XXX',
4: 'XL',
5: 'L'
};
var graphicNumbers = {
'I':['#### ',
' ## ',
' ## ',
' ## ',
'#### '],
'V':['## ## ',
'## ## ',
' ## ## ',
' #### ',
' ## '],
'X':['## ## ',
' ## ## ',
' ### ',
' ## ## ',
'## ## '],
'L':['## ',
'## ',
'## ',
'## ',
'####### '],
':':[' ',
'## ',
' ',
'## ',
' '],
'-':[' ',
' ',
'######## ',
' ',
' ']
};
var hours = process.argv[2];
var minutes = process.argv[3];
var isInt = function(n) {return Number(n) === parseInt(n);};
if(!isInt(hours) || !isInt(minutes)){
process.exit(1);
} else {
var time = getRomanTime(hours, minutes);
console.log(time);
printNumber(time);
}
function getRomanTime(hours, minutes){
if (0 < hours && hours < 23 && 0 < minutes && minutes < 59) {
var hours1 = Math.floor(hours / 10), hours2 = hours % 10;
var minutes1 = Math.floor(minutes / 10), minutes2 = minutes % 10;
hours = higher[hours1] + lower[hours2];
minutes = higher[minutes1] + lower[minutes2];
if (hours.length === 0){
hours = '-';
}
if (minutes.length === 0){
minutes = '-';
}
return hours + ':' + minutes;
} else {
console.log("Время указано не верно");
}
}
function printNumber(time){
var result = ['', '', '', '', ''];
var char = '', add = [];
for (var i=0; i<time.length; i++){
char = time.charAt(i);
add = graphicNumbers[char];
for(var j=0; j<5; j++){
result[j] += add[j];
}
}
for(i=1; i<5; i++){
result[0] +='\n' + result[i];
}
console.log(result[0]);
}