Last active
August 11, 2020 17:34
-
-
Save seandaniel/2d711ab57aa7813988deca23745de3c6 to your computer and use it in GitHub Desktop.
3. Return the average rating of movies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let ratingsAverage = movies.map((movie) => { | |
return movie.rating; | |
}); | |
ratingsAverage = ratingsAverage.reduce((total, rating) => { | |
return (total + rating); | |
}); | |
console.log(ratingsAverage / movies.length); | |
// 8.357142857142858 | |
// equivalent to lines 1-7 | |
const ratingsAverage = movies | |
.map(movie => movie.rating) | |
.reduce((total, rating) => total + rating); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment