Use the reduce Method to Analyze Data - Confused

Use the reduce Method to Analyze Data - Confused



After few hours trying to figure it out, I finally had a working code for this challenge, but I am sure, there is way I can cut down that Array.filter out of the code.

// Add your code below this line

let NolandRatingBig = =>{
return obj.Director == "Christopher Nolan"? parseFloat(obj.imdbRating) : 0;
}); // output  [ '8.8', '8.6', '9.0', '8.3', 0 ] I could not find a way tell the function to ignore case where the Director is not "Christopher Nolan"

//Removing the unnecessary values created by the last function
let NolandRating = NolandRatingBig.filter(function(a){
  return a > 0;
}); // output [8.8, 8.6, 9, 8.3]

let a = NolandRating.reduce(function(accumulator, currentValue, currentIndex, array){
  return currentValue + accumulator;

var averageRating = a/NolandRating.length;

// Add your code above this line



Why not do the check in your reduce function and only add a value to the accumulator if it’s greater than zero?