Skip to content

Instantly share code, notes, and snippets.

@Bengejd
Last active February 6, 2019 12:09
Show Gist options
  • Save Bengejd/f948521d55f1916e980d533bbd21c712 to your computer and use it in GitHub Desktop.
Save Bengejd/f948521d55f1916e980d533bbd21c712 to your computer and use it in GitHub Desktop.
A quick and simple way to order an array of objects that have a moment.js date property, using Lodash!
import * as _ from 'lodash';
...
/*
* Group them by the formatted date below.
* The more specific this format is, the smaller the groups will become.
*/
private groupMessagesByDate(messages) {
return _(messages)
.groupBy((m: any) => m.date.format('MM/DD/YYYY'))
.map((value, key) => ({date: key, messages: value})) // Map them out
.value();
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment