My task involves extracting the key puppies
from an array of objects and returning it in a new array:
The input is an array of dogs structured like this:
[
{breed: 'Labrador', puppies: ['Fluffy', 'Doggo', 'Floof'] },
{breed: 'Rottweiler', puppies: ['Biscuits', 'Mary'] }
]
The goal is to create an array containing all the puppies from all the dogs:
['Fluffy', 'Doggo', 'Floof', 'Biscuits', 'Mary']
This is the code I have written so far:
function collectPuppies (dogs) {
let solution=[];
for(let i=0; i<dogs.length; i++){
solution.push(dogs[i].puppies);
}
return solution;
}
Although it adds the names to the solution, they are returned within double brackets [[ ]]
:
Expected [ [ 'Spot', 'Spotless' ] ] to deeply equal [ 'Spot', 'Spotless' ]
I came across a similar solution in this thread, indicating that I may be on the right track but struggling to pinpoint my mistake. Any assistance would be greatly appreciated. Thank you.