`hours = ["3:42am", "6:37pm", "1:24pm", "2:11am", "8:30am", "1:51am", "12:03am", "11:18pm", "12:28pm", "3:46am", "10:27pm", "9:47am", "12:07am", "8:28pm", "8:41am", "10:43pm", "11:55pm", "10:57pm", "12:43pm"] function SplitHours(hours) { let hourObject = {} let hour = [] let minute = [] let hourPeriod = [] let i for (i = 0; i < hours.length; i += 1) { hour[i] = parseInt(hours[i].match(/^[^\:]*/gi)[0]) minute[i] = parseInt(hours[i].match(/[^:]*(?=pm|am)/gi)[0]) hourPeriod[i] = hours[i].match(/([A-Za-z])\w+/gi)[0] if (hourPeriod[i] == "pm" && !(parseInt(hour[i]) == 12)) { hour[i] = parseInt(hour[i]) + 12 } hour[i] = minute[i] > 30 ? hour[i] + 1 : hour[i] if (hour[i] == 13 && hourPeriod[i] == "am") { hour[i] = 1; hourPeriod[i] = "pm" } else if (hour[i] == 13 && hourPeriod[i] == "pm") { hour[i] = 1; hourPeriod[i] = "am" } } hourObject.hour = hour return hourObject } `

I am just trying to rewrite hours; say 1:24pm, if 24 > 30 then it is 2pm, otherwise it is 1pm.

I really doubt that I am doing it right, first I am sure it looks so amateur, second I am not sure if it is optimised.

Can you provide me a better approach to this?

This is also on: http://codereview.stackexchange.com/questions/95096/javascript-editing-hours as I am not sure where this belongs to.