← Back to the exercise

Array Methods: map, filter, reduce

The answer to the exercise in Array Methods: map, filter, reduce.

goodTitles held the shows themselves, so each log printed an object. filter narrows the list to the streaming shows above 8, and map turns each survivor into its title. The rating lives one level down, so the condition reads show.rating.average, not show.rating.

const shows = [
  { title: "Severance", streaming: true, rating: { average: 8.7 } },
  { title: "Andor", streaming: false, rating: { average: 8.4 } },
  { title: "Shogun", streaming: true, rating: { average: 8.9 } },
  { title: "Kaos", streaming: true, rating: { average: 7.2 } },
];

const goodTitles = shows // was: const goodTitles = shows;
  .filter((show) => show.streaming && show.rating.average > 8)
  .map((show) => show.title);

goodTitles.forEach((title) => console.log(title));