Last active
February 6, 2019 12:09
-
-
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!
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
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