I've got some code there is handling an array of objects called into the function. I've got it to work mostly but when I call the function with a multiarray it doesn't return the expected values and just one of them.
Can you please fix the code and explain to me where I've gone wrong? Thank you!
function petPower(people) {
let rest = people.reduce((a, b) => a && b.pets, []);
return rest;
}
console.log(petPower([
{ name: 'Brain', pets: ['Doggy', 'Minuuy'] },
{ name: 'Carla', pets: ['Hammy', 'Hamishy'] },
]));
I want the above to return ['Doggy', 'Minuuy', 'Hammy', 'Hamishy'] but it's only returning Hammy and Hamishy.