Https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-use-the-reduce-method-to-analyze-data/301313

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