Created
October 20, 2019 23:02
-
-
Save dottedsquirrel/e415e83fb18bb704ba0711eb4304c746 to your computer and use it in GitHub Desktop.
Using sort() on months
This file contains 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
var someItems = ["Feb", "Jan", "Apr", "Dec", "Oct"]; | |
function sortMonths(a, b){ | |
var correctMonthsOrder = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; | |
return correctMonthsOrder.indexOf(a) - correctMonthsOrder.indexOf(b); | |
} | |
someItems.sort(sortMonths); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment