0

For a project I'm currently working on I have to create a timeline page with items that are sorted by time. It's all taking place on a single day so I don't have to take dates into consideration!

My project does include moment.js if that could be of any help.

My initial thoughts were to convert them back into seconds -> arrange the array from lowest to highest -> revert them back to HH:mm format. But I'm not sure if this is a good option.

Example array

['11:00:00', '10:45:00', '09:00:00', '12:00:00']

Should become

['09:00:00', '10:45:00', '11:00:00', '12:00:00']

Note: In my current project I'm working with more than 50 items on 1 day. So this is just a small example size. But it should be enough for me to get the general idea.

Thanks in advance

Tbmluijten
  • 113
  • 1
  • 3
  • 12
  • 1
    considering the strings are nicely formatted (hh:mm:ss) a simple `array.sort()` will do ... e.g. `['11:00:00', '10:45:00', '09:00:00', '12:00:00'].sort()` – Jaromanda X May 04 '20 at 08:35
  • Note, I'm aware marked dupe has array of object, but should address the sorting logic – Rajesh May 04 '20 at 08:38

0 Answers0