function timeConversion(s) {
/*
* Write your code here.
*/
const ampm = s.slice(-2)
let hours = Number(s.slice(0, 2))
if (s.slice(-2) === "AM") {
if (hours === 12) {
hours = 0
}
} else {
if (hours < 12) {
hours += 12
}
}
return hours.toString().padStart(2, "0") + s.slice(2, -2)
}
Time Conversion
November 21, 2019 • ☕️ 1 min read
algorithm/hackerrank