Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve (input) {
- let coutOfMovies = Number(input.shift());
- let highestRating = Number.MIN_SAFE_INTEGER;
- let minimunRating = Number.MAX_SAFE_INTEGER;
- let averageRating = 0;
- let ratingNameHigh = '' ;
- let nameLow = '' ;
- for(let i = 0; i < coutOfMovies ; i++) {
- let name = input.shift();
- let rating = Number(input.shift());
- averageRating += rating;
- if(rating > highestRating) {
- highestRating = rating;
- ratingNameHigh = name;
- } else {
- minimunRating = rating;
- nameLow = name;
- }
- }
- averageRating = averageRating / coutOfMovies;
- console.log(`${ratingNameHigh} is with highest rating: ${highestRating}`)
- console.log(`${nameLow} is with lowest rating: ${minimunRating}`)
- console.log(`Average rating: ${averageRating.toFixed(1)}`)
- }
Advertisement
Add Comment
Please, Sign In to add comment