Advertisement
didkoslawow

Untitled

Feb 17th, 2023
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bonusScoringSystem(input) {
  2.     const studentsInfo = input.map(x => Number(x));
  3.     const studentsCount = studentsInfo.shift();
  4.     const lecturesCount = studentsInfo.shift();
  5.     const bonus = studentsInfo.shift();
  6.     let totalBonus = 0;
  7.     let maxAttendances = 0;
  8.  
  9.     for (const attendances of studentsInfo) {
  10.         let currentMaxBonus = maxBonus(attendances, lecturesCount, bonus);
  11.  
  12.         if(currentMaxBonus >= totalBonus) {
  13.             totalBonus = currentMaxBonus;
  14.             maxAttendances = attendances;
  15.         }
  16.     }
  17.    
  18.     console.log(`Max Bonus: ${Math.ceil(totalBonus)}.`);
  19.     console.log(`The student has attended ${maxAttendances} lectures.`);
  20.  
  21.     function maxBonus(attendances, lecturesCount, bonus) {
  22.         const totalBonus = attendances / lecturesCount * (5 + bonus);
  23.         return totalBonus;
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement