I have following JSON data and trying to calculate the total price of each year:

```
const data = [
  { year: 2020, price: 400 },
  { year: 2019, price: 20 },
  { year: 2020, price: 100 },
  { year: 2019, price: 80 },
]

```

I wrote the following code to calculate the price but the result is incorrect.

```
const price = data.reduce((acc, current) => {

  if(!acc[current.year]) {
    acc[current.year] =  current.price;
  }

  acc[current.year] += current.price;

  return acc;

}, {});

```

How do I fix the code and what's my problem?

Also, are the following meaning same? I don't understand the syntax of (acc[item.color] || 0) part.

```
const test1 = data.reduce((acc, item) => {
  acc[item.color] = (acc[item.color] || 0) + 1;
  return acc;
}, {});

```

```
const test2 = data.reduce((acc, item) => {

  if(!acc[item.color]) {
    acc[item.color] = 0;
  }

  acc[item.color] = acc[item.color] + 1;
  return acc;
}, {});

```