-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheTimeInWords.js
84 lines (70 loc) · 1.7 KB
/
TheTimeInWords.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
// This function will take the time as an integer, split as two arguements (hour and minutes)
// It will then return the time in words
// This code is garbage, far from dry and I'll need to come back to clean it but it was my first "medium" challenge completed :)
function timeInWords(h, m) {
let timeString;
let wArray = [
" o' clock",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
"fourteen",
"fifteen",
"sixteen",
"seventeen",
"eighteen",
"nineteen",
"twenty",
"minute",
"quarter ",
"half ",
"quarter ",
"past ",
"to "
];
// oclock
if (m === 0) {
return wArray[h].concat(wArray[0]);
}
// quarter past
if (m === 15) {
return wArray[22].concat(wArray[25] + wArray[h]);
}
if (m === 30) {
return wArray[23].concat(wArray[25] + wArray[h]);
}
if (m === 45) {
return wArray[22].concat(wArray[26] + wArray[h + 1]);
}
if (m === 1) {
return wArray[1].concat(" " + wArray[21] + " " + wArray[25] + wArray[h]);
}
if (m < 30) {
if (m > 20) {
let newMin = m.toString();
return wArray[20].concat(" " + wArray[newMin[1]] + " " + wArray[21] + "s " + wArray[25] + wArray[h]);
}
return wArray[m].concat(" " + wArray[21] + "s " + wArray[25] + wArray[h]);
}
if (m > 30) {
let newNum = 60 - m;
if (newNum > 20) {
let newMin = m.toString();
return wArray[20].concat(" " + wArray[newMin[1]] + " " + wArray[21] + "s " + wArray[26] + wArray[h + 1]);
}
return wArray[newNum].concat(
" " + wArray[21] + "s " + wArray[26] + wArray[h + 1]
);
}
return h;
}