Movie rating Javascript
https://softuni.bg/downloads/svn/programming-basics-v4/course-content/course-resources/Exam-Preparation-Second.pdf
Един от няколкото варианта. Може да бъде пооправен но не това е въпроса.
Джъдж ми дава 33/100.
При грешен вариант в който " } else if (rating <= lowestRating) { " "lowestRating беше заменен с highestRating" му даде 60/100.
function solve(input) {
let filmNums = Number(input.shift());
let name = input.shift();
let rating = Number(input.shift());
let highestRating = 0;
let highName = ``;
let lowestRating = 11;
let lowestName = ``;
let averageRating = 0;
for (i = 1; i <= filmNums; i++) {
if (rating === highestRating || i === 1) {
lowestRating = rating;
lowestName = name;
highestRating = rating;
highName = name;
averageRating += rating;
name = input.shift();
rating = Number(input.shift());
} else if (rating >= highestRating ) {
highestRating = rating;
highName = name;
averageRating += rating;
name = input.shift();
rating = Number(input.shift());
} else if (rating <= lowestRating) {
lowestRating = rating;
lowestName = name;
averageRating += rating;
name = input.shift();
rating = Number(input.shift());
}
}
console.log(`${highName} is with highest rating: ${(highestRating).toFixed(1)}`);
console.log(`${lowestName} is with lowest rating: ${(lowestRating).toFixed(1)}`);
console.log(`Average rating: ${(averageRating / filmNums).toFixed(1)}`);
}