Skip to content

Instantly share code, notes, and snippets.

@chollier
Created January 29, 2015 22:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chollier/f53afc91544cff3c1e51 to your computer and use it in GitHub Desktop.
Save chollier/f53afc91544cff3c1e51 to your computer and use it in GitHub Desktop.
Immutable.js sorting
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();
@chollier
Copy link
Author

I also tried with .unix() instead of .toDate() but I'm getting the same unordered results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment