//Before
export const arr1 = [
{ addKey: '11', address: '12', value: 0 },
{ addKey: '11', address: '12', value: 0 },
{ addKey: '12', address: '11', value: 0 },
{ addKey: '12', address: '11', value: 0 },
]
export const arr2 = [
{address: '11', value: 5, total: 0 },
{address: '12', value: 10, total: 0 },
]
I want to create a function with arr1 & arr2 as arguments.
Where arr1.address == arr2.address => take arr2.value => Put in arr1.value
Sum the values by addKey then add to arr2.total
//After
export const arr1After = [
{ addKey: '11', address: '12', value: 10 },
{ addKey: '11', address: '12', value: 10 },
{ addKey: '12', address: '11', value: 5 },
{ addKey: '12', address: '11', value: 5 },
]
export const arr2After = [
{address: '11', value: 5, total: 20 },
{address: '12', value: 10, total: 10 },
]
addressdistinct inarr2After?