I have 3 objects, they have a "cost" key which is array of objects. As a result, I want to have a "main" which will stay the same except its "value" will be a diff of this value minus other objects "value"
const main = {
cost: [
{ id: 'main', value: 20, timestapm: 'asd', current: '10'},
{ id: 'main', value: 10, timestapm: 'asd', current: '10'},
{ id: 'main', value: 18, timestapm: 'asd', current: '10'},
],
description: 'maindevice',
total: 5
}
const other = {
cost: [
{ id: 'device1', value: 10, timestapm: 'qwe', current: '10'},
{ id: 'device1', value: 5, timestapm: 'qwe', current: '10'},
{ id: 'device1', value: 9, timestapm: 'qwe', current: '10'},
],
description: 'maindevice',
total: 3
}
const other2 = {
cost: [
{ id: 'device2', value: 5, timestapm: 'zxc', current: '10'},
{ id: 'device2', value: 2, timestapm: 'zxc', current: '10'},
{ id: 'device2', value: 2, timestapm: 'zxc', current: '10'},
],
description: 'maindevice',
total: 6
}
const devices = [main, other, other2];
result i want to have =>
main = {
cost: [
{ id: 'main', value: 5, timestapm: 'asd', current: '10'},
{ id: 'main', value: 3, timestapm: 'asd', current: '10'},
{ id: 'main', value: 7, timestapm: 'asd', current: '10'},
],
description: 'maindevice',
total: 5
}
main?