Skip to content

Instantly share code, notes, and snippets.

@seandaniel
Last active August 11, 2020 17:34
Show Gist options
  • Save seandaniel/2d711ab57aa7813988deca23745de3c6 to your computer and use it in GitHub Desktop.
Save seandaniel/2d711ab57aa7813988deca23745de3c6 to your computer and use it in GitHub Desktop.
3. Return the average rating of movies
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