Last active
January 10, 2023 16:59
-
-
Save Angelfire/231a926af20d1be451a0fc5706c33858 to your computer and use it in GitHub Desktop.
Sort By Months
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MONTHS = [ | |
'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', | |
'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC' | |
]; | |
const events = [{ event: 'dance', month: 'MAR' }, | |
{ event: 'farmers market', month: 'JUN' }, | |
{ event: 'parade', month: 'JAN' }] | |
function sortByMonth(events) { | |
return events.sort((a, b) => MONTHS.indexOf(a.month) - MONTHS.indexOf(b.month)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment