Functional Programming - Use the reduce Method to Analyze Data

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:

…find the average IMDB rating of the movies directed by Christopher Nolan

A big part of being a good dev is paying attention to tiny details. I often read and reread and rereread specs to make sure I get every little detail.

Man, that’s what happens when I try to study while sleep-deprived. Thanks for catching that.

Sure, it’s a common mistake. I mean this specifically is a common mistake on this specific challenge, but also in general, you learn to read things very closely and very exactly. When in doubt, reread. Even if you aren’t in doubt, reread just to be sure. For a long time, most of the tickets I got returned at work were because I didn’t read the specs or bug report or repo steps closely enough.