Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created July 31, 2019 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongorman/c05ff784552cdd5b2f0c57707dfc73b4 to your computer and use it in GitHub Desktop.
Save jasongorman/c05ff784552cdd5b2f0c57707dfc73b4 to your computer and use it in GitHub Desktop.
class Reviews {
constructor(){
this.reviews =[];
}
leaveReview(review, cd){
if(!review.customerHas(cd)){
throw new NotInCustomerCollectionError();
}
this.reviews.push(review);
}
averageRating(){
return this.sumOfRatings()
/this.reviews.length;
}
sumOfRatings() {
return this.reviews
.map((review) => review.rating)
.reduce((sum, rating) => sum + rating);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment