Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(grades) {
- grades = grades.map(Number);
- let studentsNumber = grades.shift();
- let sumAllGrades = 0;
- let lowOrEq2_99 = 0;
- let lowOrEq3_99 = 0;
- let lowOrEq4_99 = 0;
- let bigOrEq5 = 0;
- for (let grade of grades) {
- if (grade < 2 || grade > 6) {
- continue;
- }
- if (grade <= 2.99) {
- lowOrEq2_99++;
- } else if (grade <= 3.99) {
- lowOrEq3_99++;
- } else if (grade <= 4.99) {
- lowOrEq4_99++;
- } else {
- bigOrEq5++;
- }
- sumAllGrades += grade;
- }
- let averageGrade = (sumAllGrades / studentsNumber).toFixed(2);
- let percentFailed = (lowOrEq2_99 / studentsNumber) * 100;
- let percent3_99 = (lowOrEq3_99 / studentsNumber) * 100;
- let percent4_99 = (lowOrEq4_99 / studentsNumber) * 100;
- let percent5 = (bigOrEq5 / studentsNumber) * 100;
- console.log(`Top students: ${percent5.toFixed(2)}%`);
- console.log(`Between 4.00 and 4.99: ${percent4_99.toFixed(2)}%`);
- console.log(`Between 3.00 and 3.99: ${percent3_99.toFixed(2)}%`);
- console.log(`Fail: ${percentFailed.toFixed(2)}%`);
- console.log(`Average: ${averageGrade}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement