I am trying to solve this problem a piece at a time with the following:
(Credit to pseudospencer for his approach to the problem. )
// create a list of Christopher Nolan movies
let CNmovies = watchList.filter(movie => movie.Director == “Christopher Nolan”);
// reduce to the sum of all of his movie ratings
let allRatingsSummed = CNmovies.reduce((acc, movie) => acc + parseFloat(movie.imdbRating));
But this is resulting in allRatingsSummed looking like this in the console:
object Object]8.698.3
I’m getting the imdbRatings appended to each other rather than summed. (???) And the first movie object seems to be missing altogether. But if I could just get the ratings to be treated as numbers, I would be happy for now. Note: I have tried both using the parseFloat() and Number() functions to convert the rating to a number.
Does anyone see what I’m doing wrong?
Thanks!