AreWe

Movie Ratings

Jan 17th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. (input) => {
  2. const times = +input.shift();
  3. let highestName = '', highestRating = 0,
  4. lowestName = '', lowestRating = 11,
  5. sum = 0;
  6.  
  7. for(let i=0; i<times; i++) {
  8. let name = input.shift(), rating = +input.shift();
  9.  
  10. if(rating > highestRating) {
  11. highestRating = rating;
  12. highestName = name;
  13. }
  14. if(rating < lowestRating) {
  15. lowestRating = rating;
  16. lowestName = name;
  17. }
  18.  
  19. sum += rating;
  20. }
  21.  
  22. const average = (sum/times).toFixed(1);
  23.  
  24. console.log(`${highestName} is with highest rating: ${highestRating}`);
  25. console.log(`${lowestName} is with lowest rating: ${lowestRating}`);
  26. console.log(`Average rating: ${average}`);
  27. }
Add Comment
Please, Sign In to add comment