I have a list of strings that I want to use as duration filter options. They are currently sorted alphabetically but I want them to be sorted by length of time. Is this possible?
The strings are:
[‘1 day’, ‘2 days’, ‘2 weeks’, ‘3 days’, ‘3 hours’, ‘4 days’]
What I want is:
[‘3 hours’, ‘1 day’, ‘2 days’, ‘3 days’, ‘4 days’, ‘2 weeks’]
Currently i’m sorting them alphabetically by:
const durations = [...new Set(this.courses.map(item => item.fields.duration).sort((a, b) => a.localeCompare(b)))];