- Can you explain what the sum equals specifically? (It seems it’s almost always sum so far so I got the solution, but I’m not understanding what is being added to the ratings)
- Why was
0
needed? - Am I correct in my understanding of the other arguments below?
- accumulator is
sum
- currentValue is
movie
- index is not needed
- array is not needed
- initialValue is
0
Your code so far
function getRating(watchList){
// filters movies for those directed by Christopher Nolan
var cNolan = watchList.filter(movie => movie["Director"] == "Christopher Nolan")
// uses reduce to get the average IMDB rating
var averageRating = cNolan.reduce((sum,movie) => {
return sum + parseFloat(movie.imdbRating);
}, 0) / cNolan.length;
// Only change code above this line
return averageRating;
}
console.log(getRating(watchList));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36
.
Challenge: Use the reduce Method to Analyze Data
Link to the challenge: