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
This commit is contained in:
committed by
Randell Dawson
parent
0ee212d5af
commit
a30982e862
@ -120,8 +120,15 @@ 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
|
||||
|
||||
|
Reference in New Issue
Block a user