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:

Your solution is fine. It is fine to add extra variables to clarify what is happening in the code. If it makes the code more readable, there is nothing wrong with extra variables.

1 Like

Thanks for the quick response!