Hello -
This challenge asks us to use the reduce method to get the average of five ratings. Those ratings are: 8.8, 8.6, 9.0, 8.3, and 7.9.
The average of those would be 8.52. However, the challenge wants us to somehow get 8.675.
My solution gets the correct average, but for some reason the solutions given are much more complicated, and do not return the actual average.
What am I misunderstanding here?
My solution is below.
function getRating(watchList) {
// Only change code below this line
let averageRating;
averageRating = watchList.reduce((acc, movie) => acc + Number(movie.imdbRating), 0);
averageRating = averageRating / watchList.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/106.0.0.0 Safari/537.36
Challenge: Functional Programming - Use the reduce Method to Analyze Data
Link to the challenge: