ExGiX

Untitled

Mar 27th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. function solve (input) {
  2.  
  3. let coutOfMovies = Number(input.shift());
  4.  
  5. let highestRating = Number.MIN_SAFE_INTEGER;
  6. let minimunRating = Number.MAX_SAFE_INTEGER;
  7. let averageRating = 0;
  8. let ratingNameHigh = '' ;
  9. let nameLow = '' ;
  10.  
  11.  
  12. for(let i = 0; i < coutOfMovies ; i++) {
  13. let name = input.shift();
  14. let rating = Number(input.shift());
  15. averageRating += rating;
  16.  
  17. if(rating > highestRating) {
  18. highestRating = rating;
  19. ratingNameHigh = name;
  20.  
  21. } else {
  22. minimunRating = rating;
  23. nameLow = name;
  24.  
  25. }
  26.  
  27. }
  28.  
  29. averageRating = averageRating / coutOfMovies;
  30. console.log(`${ratingNameHigh} is with highest rating: ${highestRating}`)
  31. console.log(`${nameLow} is with lowest rating: ${minimunRating}`)
  32. console.log(`Average rating: ${averageRating.toFixed(1)}`)
  33.  
  34.  
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment