Is this a decent solution? Functional Programming - Use the reduce Method to Analyze Data

Tell us what’s happening:
I felt okay about this solution, but when I looked at the two solutions given by fCC I noticed that neither of them declares two variables. Is it okay to do this? I’m glad I was able to solve it, but I’d like to keep to best practices.

Your code so far

function getRating(watchList) {
  // Only change code below this line
  let nolanFilms = watchList.filter(movie => 
    movie.Director === "Christopher Nolan"
  )
  let averageRating = nolanFilms.reduce((sum, movie) => 
    sum + parseFloat(movie.imdbRating), 0
  ) / nolanFilms.length
  // Only change code above this line
  return averageRating;
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36

Challenge: Functional Programming - Use the reduce Method to Analyze Data

Link to the challenge:

Thanks for the quick response!

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