DEV Community

Discussion on: How I work with arrays

Collapse
 
danielm profile image
Daniel Mejía Raigosa

Nice post. On the reduce I would refactor the code as

const tally = fruits.reduce((tally, fruit) => {
  tally[fruit] = tally[fruit] || 1
  tally[fruit] += 1
  return tally
}, {});

I'm on mobile so didn't tested, but usually that's how I do it