Created
March 9, 2018 17:15
-
-
Save fastmover/a8cf64c0c6aab751cadede05af79f4c5 to your computer and use it in GitHub Desktop.
Sort dates in an array using moment.js
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 ordered = {}; | |
selectedDays.sort((one, two) => { | |
let ts1 = moment(one.getTime()).unix(); | |
let ts2 = moment(two.getTime()).unix(); | |
if(ts1 < ts2) | |
return -1; | |
if(ts1 > ts2) | |
return 1; | |
return 0 | |
}).forEach((key) => { | |
ordered[key] = selectedDays[key] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment