Hello everyone !
I’ve written this :
let seriesToWatch = [
{ "Title": "Breaking bad",
"Year": "2007",
"Seasons": "8",
"Episodes": "130",
"Actor": "Walter White",
"Rate": "10",
"Director": "Mandiaye Ndiaye"
},
{ "Title": "Casa de papel",
"Year": "2018",
"Seasons": "3",
"Episodes": "50",
"Actor": "Profesor",
"Rate": "7",
"Director": "Mandiaye Ndiaye"
},
{ "Title": "Game of Throne",
"Year": "2011",
"Seasons": "8",
"Episodes": "90",
"Actor": "Jon snow",
"Rate": "9",
"Director": "Mandiaye Ndiaye"
}
];
I want to get the titles and ratings of the movies that have a rating greater than 8.
As a solution, I use map and filter:
let filteredList = seriesToWatch
.map(e => ({
title: e["Title"],
rating: e["Rate"]
}))
.filter(e => e.rating > 8);
console.log(filteredList);
Good, it worked but a post by freeCodeCamp said that :"If you chain map and filter together you are doing the work twice. You filter every single value and then you map the remaining values. With reduce you can filter and then map in a single pass.
Use map and filter but when you start chaining lots of methods together you now know that it is faster to reduce the data instead."
So I don’t know how to do it with reduce method.
I start with this, but I have no idea what to put in.
const film = seriesToWatch.reduce((title, actor) => {
help please !
}, {});