In code, we first split the string into two parts, time and part. We then use the index of the PM symbol in the string to change the 12 to 12 PM. If the part of the string is not PM, it is set to the first 12 of the string. We then use the index of the AM symbol in the string to change the 0 to 12 AM. Finally, we join the parts together with a space.
function timeConversion(s) {
let [time, part] = [s.substring(0, s.length - 2), s.substring(s.length - 2)]
time = time.split(":").map(Number)
if (part === "PM" && time[0] === 12) time[0] = 12
if (part === "PM" && time[0] !== 12) time[0] = (time[0] + 12) % 24
if (part === "AM" && time[0] === 12) time[0] = 0
return time
.map(String)
.map(s => s.padStart(2, "0"))
.join(":")
}