I have an array of JSON Objects that looks like the below sample:
[ { _id: 58d98fc46cb2342d6848ae3,
updateNumber: '1',
resolution: 'tbd',
nextUpdate: Mon Mar 27 2017 17:06:00 GMT-0400 (EDT),
update: 'update 1',
subject: 'test1',
impact: 'test1',
incidentNumber: '12345',
wasNew: true,
__v: 0 },
{ _id: 58d880126fb5087d684c8de4,
updateNumber: '2',
resolution: 'tbd',
nextUpdate: Mon Mar 27 2017 18:06:00 GMT-0400 (EDT),
update: 'update 2',
subject: 'test1',
impact: 'test1',
incidentNumber: '12345',
wasNew: true,
__v: 0 },
{ _id: 58c23ae21bt2743d6328ae3,
updateNumber: '1',
resolution: 'tbd',
nextUpdate: Mon Mar 27 2017 17:06:00 GMT-0400 (EDT),
update: 'update 1',
subject: 'test2',
impact: 'test2',
incidentNumber: '23456',
wasNew: true,
__v: 0 } ]
What I need to be able to do is for each incidentnumber, grab the latest update. Each incidentNumber will have multiple updates and I want to be able to retrieve the latest update (In the above example that is update 2 for incidentNumber 12345 and update 1 for incidentNumber 23456)
So far I have tried variations of _.max which will only work for one incidentNumber and not multiple.
I have searched extensively and so far have not found any questions that involved the same dataset I have.
Can anyone point me in the right direction on how to start solving this problem?
Thanks
updateNumber. You just need to store the list Index for the highest where theupdateNumber. then you know where in the list you need to get theincidentNumber`.