From a30982e862e241a4f4615211ef0c14543a77b1e2 Mon Sep 17 00:00:00 2001 From: Gerard Hynes Date: Sun, 19 May 2019 18:45:34 +0100 Subject: [PATCH] Add comments and update callback arguments' names (#36082) * Add comments and update callback arguments' names I've added a few comments to the solution and given the callback arguments more descriptive names to clarify what the solution is doing, since this challenge seemed a little more complex than the previous challenges. * Update guide/english/certifications/javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data/index.md That makes absolute sense and is clearer. Thank you. Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Update indentation to be two-spaced --- .../use-the-reduce-method-to-analyze-data/index.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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); ```