Imagine having 3 objects, each with a "cost" key that contains an array of objects. The goal is to create a new object called "main" where the "value" in each item will be the difference between its value and the values of other objects.
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];
desired result:
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
}