I have a list of strings of the form:
CLUB1_20201008_EVE
CLUB1_20201008_AFT
CLUB1_20201008_AM
CLUB1_20201008_AM2
CLUB1_20201008_PM
CLUB1_20201008_NIGHT
CLUB2_20201008_EVE
CLUB2_20201008_AFT
CLUB2_20201008_AM
CLUB2_20201008_AM2
CLUB2_20201008_PM
CLUB2_20201008_NIGHT
I can get the sort to work by club name and date but the time of day needs to be sorted like AM,AM2,AFT,PM,EVE,NIGHT. These are obviously unsortable since their sequence is not alphabetical.
How do I use an auxiliary array to get them to sort in the proper order?
Thanks,Milt
Expected Output CLUB1_20201008_NIGHT CLUB2_20201008_NIGHT CLUB1_20201008_EVE CLUB2_20201008_EVE CLUB1_20201008_PM CLUB2_20201008_PM CLUB1_20201008_AFT CLUB2_20201008_AFT CLUB1_20201008_AM2 CLUB2_20201008_AM2 CLUB1_20201008_AM CLUB2_20201008_AM
One way is to use a hash table that maps the strings to their numerical order, and then comparing based on that:
Wikipedia has information on the Schwartzian Transform if you haven't seen that idiom for sorting before.