Advertisement
Malinov

Untitled

Jun 9th, 2021
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function test(arr){
  2.  
  3.     let studentsCount = Number(arr.shift());
  4.     let lectureCount = Number(arr.shift());
  5.     let initialBonus = Number(arr.shift());
  6.  
  7.     let totalBonus = 0;
  8.    
  9.     let maxBonus = 0;
  10.     let lectures = 0;
  11.     let studentAttendances = '';
  12.  
  13.     for (let i = 0; i < arr.length; i++) {
  14.  
  15.         studentAttendances = Number(arr[i]);
  16.        
  17.         totalBonus = (studentAttendances / lectureCount) * (5 + initialBonus);
  18.  
  19.         if(maxBonus > totalBonus){
  20.             continue;
  21.         } else {
  22.             maxBonus = totalBonus;
  23.             lectures = studentAttendances;
  24.         }
  25.        
  26.     }
  27.  
  28.     console.log(`Max Bonus: ${Math.ceil(maxBonus)}.`);
  29.     console.log(`The student has attended ${lectures} lectures.`);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement