Hackerrank: Time Conversion Solution
1function timeConversion(s) {2 let [time, part] = [s.substring(0, s.length - 2), s.substring(s.length - 2)]3 time = time.split(":").map(Number)4 if (part === "PM" && time[0] === 12) time[0] = 125 if (part === "PM" && time[0] !== 12) time[0] = (time[0] + 12) % 246 if (part === "AM" && time[0] === 12) time[0] = 07 return time8 .map(String)9 .map(s => s.padStart(2, "0"))10 .join(":")11}
Comments
Loading comments...
Tags
hackerrank
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.