misha.korolcov,
const arrOne = [{
city: '111',
price: 1
},
{
city: '222',
price: 2
},
]
const arrTwo = [{
city: '111',
price: 0
},
{
city: '333',
price: 0
},
{
city: '444',
price: 0
},
]
const res = (...arr) => {
const obj = {};
return arr.flat().filter(ob => {
let {
city,
price
} = ob;
if (obj[city]) {
obj[city].price += price;
return false
} else {
obj[city] = ob
};
return true
})
}
console.log('res', res(arrOne, arrTwo))