Thứ Bảy, 29 tháng 2, 2020

[Hackerrank] Solution of The Time in Words in JavaScript

[Hackerrank] Solution of The Time in Words in JavaScript

[Hackerrank] Solution of The Time in Words in JavaScript
[Hackerrank] Solution of The Time in Words in JavaScript
const array = [
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
"fourteen",
"fifteen",
"sixteen",
"seventeen",
"eighteen",
"nineteen",
"twenty",
"twenty one",
"twenty two",
"twenty three",
"twenty four",
"twenty five",
"twenty six",
"twenty seven",
"twenty eight",
"twenty nine"
]
if (m === 0) {
return array[h] + " o' clock"
}
if (m === 15) {
return 'quarter past' + ' ' + array[h]
}
if (m === 30) {
return 'half past' + ' ' + array[h]
}
if (m === 45) {
return 'quarter to' + ' ' + array[h + 1]
}
if (m < 30) {
if (m === 1) {
return array[m] + ' minute past ' + array[h]
}
return array[m] + ' minutes past ' + array[h]
}
return array[(60 - m)] + ' minutes to ' + array[h + 1]

post written by:

Related Posts

0 nhận xét: