// Given a time in -hour AM/PM format, convert it to military (24-hour) time. // Note: - 12:00:00AM on a 12-hour clock is 00:00:00 on a 24-hour clock. // - 12:00:00PM on a 12-hour clock is 12:00:00 on a 24-hour clock. /* * Complete the 'timeConversion' function below. * * The function is expected to return a STRING. * The function accepts STRING s as parameter. */ function timeConversion(s) { // Write your code here let AMPM = s.slice(-2); let timeArr = s.slice(0, -2).split(":"); if (AMPM === "AM" && timeArr[0] === "12") { // catching edge-case of 12AM timeArr[0] = "00"; } else if (AMPM === "PM") { // everything with PM can just be mod'd and added with 12 - the max will be 23 timeArr[0] = (timeArr[0] % 12) + 12 } return timeArr.join(":"); } console.log(timeConversion('07:05:45PM'))