Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function movieRatings(input) {
- let index = 0;
- let movieVolume = Number(input[index++]);
- let maxRating = 0;
- let minRating = 10;
- let maxMovie = "";
- let minMovie = "";
- let average = 0;
- for (let i = 0; i < movieVolume; i++) {
- let movie = input[index++];
- let rating = Number(input[index++]);
- if (rating > maxRating) {
- maxMovie = movie;
- maxRating = rating;
- } else if (rating < minRating) {
- minMovie = movie;
- minRating = rating;
- }
- average += rating / movieVolume;
- }
- console.log(`${maxMovie} is with highest rating: ${maxRating.toFixed(1)}`);
- console.log(`${minMovie} is with lowest rating: ${minRating.toFixed(1)}`);
- console.log(`Average rating: ${average.toFixed(1)}`);
- }
- РЕШЕНИЕ СЪС SHIFT():
- function movieRatings(input) {
- let movieVolume = Number(input.shift());
- let maxRating = 0;
- let minRating = 10;
- let maxMovie = "";
- let minMovie = "";
- let average = 0;
- for (let i = 0; i < movieVolume; i++) {
- let movie = input.shift();
- let rating = Number(input.shift());
- if (rating > maxRating) {
- maxMovie = movie;
- maxRating = rating;
- } else if (rating < minRating) {
- minMovie = movie;
- minRating = rating;
- }
- average += rating / movieVolume;
- }
- console.log(`${maxMovie} is with highest rating: ${maxRating.toFixed(1)}`);
- console.log(`${minMovie} is with lowest rating: ${minRating.toFixed(1)}`);
- console.log(`Average rating: ${average.toFixed(1)}`);
- }
Add Comment
Please, Sign In to add comment