Created
January 29, 2015 22:28
-
-
Save chollier/f53afc91544cff3c1e51 to your computer and use it in GitHub Desktop.
Immutable.js sorting
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
myMap is something like "OrderedMap { 3636: Map { stop: "2015-01-29T22:00:00.000-08:00", }, 3637: Map { stop: "2015-01-31T22:00:00.000-08:00", ... } }" | |
myMap.sort(function(a, b) { | |
if (moment(a.get('stop_at')).unix() > moment(b.get('stop_at')).unix()) { | |
return 1; | |
} else if (moment(a.get('stop_at')).toDate() < moment(b.get('stop_at')).toDate()) { | |
return -1; | |
} else { | |
return 0; | |
} | |
}).map(function(x) { | |
return moment(x.get('stop_at')).calendar(); | |
}).toJS(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I also tried with .unix() instead of .toDate() but I'm getting the same unordered results