Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2.  
  3. let moviesQuanity = +input.shift()
  4. let movieName = input.shift()
  5. let movieRating = +input.shift()
  6. let highestRating = 0
  7. let lowestRating = 0
  8. let averageRating = 0
  9. let movieHigh = ""
  10. let movieLow = ""
  11. let min = Number.MAX_SAFE_INTEGER
  12. let max = Number.MIN_SAFE_INTEGER
  13. let ratingSum = 0
  14.  
  15. for(let i = 1; moviesQuanity >= i; i++){
  16. ratingSum += movieRating
  17.    
  18.     if(min > movieRating){
  19.         min = movieRating
  20.         movieLow = movieName
  21.         lowestRating = min
  22.     }
  23.    
  24.     if(max < movieRating){
  25.         max = movieRating
  26.         movieHigh = movieName
  27.         highestRating = max
  28.     }
  29.  
  30.     movieName = input.shift()
  31.     movieRating = +input.shift()
  32. }
  33. console.log(`${movieHigh} is with highest rating: ${highestRating.toFixed(1)}`)
  34. console.log(`${movieLow} is with lowest rating: ${lowestRating.toFixed(1)}`)
  35. console.log(`Average rating: ${(ratingSum / moviesQuanity).toFixed(1)}`)
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement