I am trying to sort my array.
The array consists of data in time format.
Array:
\'9:15 AM\', \'10:20 AM\', \'02:15 PM\'
How
My solution (For times formated like "11:00", "16:30"..)
sortTimes: function (array) {
return array.sort(function (a, b) {
if (parseInt(a.split(":")[0]) - parseInt(b.split(":")[0]) === 0) {
return parseInt(a.split(":")[1]) - parseInt(b.split(":")[1]);
} else {
return parseInt(a.split(":")[0]) - parseInt(b.split(":")[0]);
}
})
}
In case someone wanted to know haha