In the first solution, how the variable rating works, can someone explain

function getRating(watchList){
  // Add your code below this line
  const 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
  return averageRating;

Welcome to the forum!

Would you be so kind to:

  • provide link to the challenge step
  • format the code you posted, use instruction below

if you have never met the reduce function, you may want to look it up

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.