I am trying to find differences between nested number values for two successive dates. My object looks like this:
obj = [
{
id: 'rec09SOGKDp3cgcbs',
fields: { date: '2022-10-21T13:37:00.000Z', value: 10 }
},
{
id: 'rec2PVebECpT2CG18',
fields: { date: '2022-10-22T13:37:00.000Z', value: 25 }
},
{
id: 'recF2zznFNdVkr9i8',
fields: { date: '2022-10-23T13:37:00.000Z', value: 55 }
}
];
And the desired output would be:
deltas = [
{
id: 'rec2PVebECpT2CG18',
fields: {delta: 15}
},
{
id: 'recF2zznFNdVkr9i8',
fields: {delta: 30}
}
]
I tried some of the suggestions posted here but get stuck at comparing the proper objects and the nested values. Any tips on how to structure this?