.reduce examples
const pets = ['dog', 'chicken', 'cat', 'dog', 'chicken', 'chicken', 'rabbit'];
const countPets = pets.reduce((obj, pet) => {
( !obj[pet] ? obj[pet] = 1 : obj[pet]++ )
return obj;
}, {})
console.log(countPets)
/*
Output:
{
dog: 2,
chicken: 3,
cat: 1,
rabbit: 1
}
*/