Skip to content

Instantly share code, notes, and snippets.

@dottedsquirrel
Created October 20, 2019 23:02
Show Gist options
  • Save dottedsquirrel/e415e83fb18bb704ba0711eb4304c746 to your computer and use it in GitHub Desktop.
Save dottedsquirrel/e415e83fb18bb704ba0711eb4304c746 to your computer and use it in GitHub Desktop.
Using sort() on months
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