diff --git a/guide/english/certifications/javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data/index.md b/guide/english/certifications/javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data/index.md index 445b7189b4..e135ba75c7 100644 --- a/guide/english/certifications/javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data/index.md +++ b/guide/english/certifications/javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data/index.md @@ -120,11 +120,18 @@ var watchList = [ ]; // Add your code below this line - -var averageRating = watchList.filter(x => x.Director === "Christopher Nolan").map(x => Number(x.imdbRating)).reduce((x1, x2) => x1 + x2) / watchList.filter(x => x.Director === "Christopher Nolan").length; +var averageRating = watchList + // Use filter to find films directed by Christopher Nolan + .filter(film => film.Director === "Christopher Nolan") + // Use map to convert their ratings from strings to numbers + .map(film => Number(film.imdbRating)) + // Use reduce to add together their ratings + .reduce((sumOfRatings, rating) => sumOfRatings + rating) + // Divide by the number of Nolan films to get the average rating + / watchList.filter(film => film.Director === "Christopher Nolan").length; // Add your code above this line -console.log(averageRating); +console.log(averageRating); ```