I have an array of an objects with different TimeStamps, which are Moment-Objects from MomentJS.
[
{
"name": "A",
"eventDateTime": "2016-12-09 07:50:17",
},
{
"name": "B",
"eventDateTime": "2016-12-09 06:50:17",
},
{
"name": "C",
"eventDateTime": "2016-12-09 07:01:17",
}
]
Now what I need to do (There are normally more of these objects) is to first sort them and then group then by a 15 minute Interval.
So sorted I should get
[
{
"name": "B",
"eventDateTime": "2016-12-09 06:50:17",
},
{
"name": "C",
"eventDateTime": "2016-12-09 07:01:17",
},
{
"name": "A",
"eventDateTime": "2016-12-09 07:50:17",
}]
And then I need to group them starting with The first object with the Time 06:50:17. So this will be my first group where all objects should be added, which are between 06:50:17 and 07:05:17. Since the array is sorted I can just iterate until one object is older than 07:05:17.
All in all it's not hard to realize, however it should be as efficient as possible. We use Lodash.js which has many functionalities. I know of the groupBy Method, however not how to A) use MomentJS and B) Define a function inside it, which checks for intervals.
Do you guys have some tips?