Link to home
Start Free TrialLog in
Avatar of victornegri
victornegri

asked on

Sort distance_of_time_in_words hash

I have a hash with the key generated by distance_of_time_in_words. I want to be able to sort that hash chronologically instead of alphabetically. How would I do that?

i.e., the keys in my hash are "6 days", "25 days", "5 months". I want to sort it in that order but what happens is the .sort method sorts it alphabetically and puts it "25 days", "5 months", "6 days".
Avatar of Andrew Doades
Andrew Doades
Flag of United Kingdom of Great Britain and Northern Ireland image

Can you not use the DESC ASC after the .sort?
Avatar of victornegri
victornegri

ASKER

DESC and ASC don't change the way the sort function works. I need to change the sort so that it sorts chronologically and not alphabetically.

Is there a way to change the results of distance_of_time_in_words back to a date value first, sort it, and then change it back to distance_of_time_in_words?
ASKER CERTIFIED SOLUTION
Avatar of karfi
karfi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
But then how do I group by the distance_of_time_in_words value after sorting by the original date? Do I need to write a new method?
just check the other thread, maybe there is the solution.