SHARE
TWEET

dasda

ivandmpk Oct 13th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function movieRatings(inputArray) {
  2.     let moviesToWatch = (inputArray.shift());
  3.     let allRatingsSum = 0;
  4.     let highestRating = -20000;
  5.     let lowestRating = 20000;
  6.     let highestMovieTitle;
  7.     let lowestMovieTitle;
  8.  
  9.     for (let i = 1; i <= moviesToWatch; i++) {
  10.         let movieTitle = inputArray.shift();
  11.         let movieRating = inputArray.shift();
  12.         allRatingsSum += movieRating;
  13.         if (movieRating > highestRating) {
  14.             highestRating = movieRating;
  15.             highestMovieTitle = movieTitle;
  16.         }
  17.         if (movieRating < lowestRating) {
  18.             lowestRating = movieRating;
  19.             lowestMovieTitle = movieTitle;
  20.         }
  21.     }
  22.     console.log(`${highestMovieTitle} is with highest rating: ${highestRating}`);
  23.     console.log(`${lowestMovieTitle} is with lowest rating: ${lowestRating}`);
  24.     let avgRating = parseFloat(allRatingsSum) / parseFloat(moviesToWatch);
  25.     console.log(`Average rating: ${avgRating.toFixed(1)}`);
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top