# Functional Programming - Use the reduce Method to Analyze Data

Hello, I’m asked to get average rating of Christopher Nolan movies using map/filter and reduce, i’ve got filter part done(commented out since the complete ‘sentence’ didn’t work), but now i’ve no idea how to reference the filtered array in reduce so that i could divide averageRating by its length.

``````function getRating(watchList) {
// Only change code below this line
let averageRating;
//console.log(watchList.filter((movie) => movie["Director"] === "Christopher Nolan")
console.log(watchList.reduce((averageRating, movie) => averageRating + parseInt(movie["imdbRating"]), 0) / watchList.length)
// Only change code above this line
return averageRating;
}

getRating(watchList);
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36`

### Challenge Information:

Functional Programming - Use the reduce Method to Analyze Data

watchList.reduce((averageRating, movie) => averageRating + parseInt(movie[“imdbRating”]), 0) / watchList.length)

1. You have used array.filter() on line before this. But the original array is NOT modified. You can console.log it out to see.
So you need to store your filter result to a variable and proceed from there.

parseInt(movie[“imdbRating”])

1. if you convert string to integer with parseInt, the number behind decimal point will be lost. You can use Number() instead.
``````parseInt('1.4') // 1
parseInt('1.8') // 1
Number('1.4') // 1.4
Number('1.8') // 1.8
``````
1 Like

There was another similar-ish about using map and filter, wasn’t a problem there iirc.

``````function getRating(watchList) {
// Only change code below this line
let averageRating;
let nolanArr = watchList.filter((movie) => movie["Director"] === "Christopher Nolan")
averageRating = nolanArr.reduce((averageRating, movie) => averageRating + Number(movie["imdbRating"]), 0) / nolanArr.length;
// Only change code above this line
return averageRating;
}

getRating(watchList);
``````

Thanks!