I have two array of objects arr 1 and arr 2  

`arr1 = [{fruit: 'apple',count: 0}] arr2 = [{fruit: 'apple',count: 0}]`

Need to create the function which accepts arr1 and arr2 as arguments and compare the fruit name if its same need to update the count value based on the count input else push the value to the array

**sample output 1:**

Inputs:
`arr1 = [{fruit: 'apple',count: 10}] arr2 = [{fruit: 'apple',count: 30},{fruit: 'orange',count: 20}]`

Output:
`[{fruit: 'apple',count: 40},{fruit: 'orange',count: 20}]`

**sample output2**

Inputs:
`arr1 = [{fruit: 'apple',count: 15}] arr2 = [{fruit: 'orange',count: 20}]`

Output:
`[{fruit: 'apple',count: 15},{fruit: 'orange',count: 20}]`

code that i have tried:

```
function compareAndUpdateCount(arr1, arr2) {
    for (i = 0; i < arr1.length; i++) {
        if (arr1[i].fruit === arr2[i].fruit) {
            arr1[i].count = arr1[i].count + arr2[i].count;
        } else {
            arr1.push(arr2[i])
        }
    }
}

```

This works fine when the array lengths are same ,if its different need help on writing the optimise code and also the reduce time complexity if we have more data