Advertisement
ErolKZ

Untitled

Oct 17th, 2021
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. function solve(arr) {
  2.  
  3. arr = arr.map(Number);
  4.  
  5. let numOfStud = arr[0];
  6.  
  7. let totalNumOfLect = arr[1];
  8.  
  9. let addBonus = arr[2];
  10.  
  11. let totalBonus = 0;
  12.  
  13. let maxBonusPoints = [];
  14.  
  15. let attendances = 0;
  16.  
  17. let arr2 = [];
  18.  
  19. arr.splice(0, 3);
  20.  
  21. // console.log(arr);
  22.  
  23.  
  24. for (let i = 0; i < arr.length; i++) {
  25.  
  26. totalBonus = arr[i] / totalNumOfLect * (5 + addBonus);
  27.  
  28. attendances = arr[i];
  29.  
  30. maxBonusPoints.push([Math.ceil(totalBonus), attendances]);
  31.  
  32. }
  33.  
  34. // console.log(maxBonusPoints);
  35.  
  36. maxBonusPoints.forEach(num => arr2.push(num[0]));
  37.  
  38. // console.log(arr2);
  39.  
  40. maxBonusPoints.forEach(num => num[0] === Math.max(...arr2) ? attendances = num[1] : false);
  41.  
  42.  
  43. console.log(`Max Bonus: ${Math.max(...arr2)}.`);
  44.  
  45. console.log(`The student has attended ${attendances} lectures.`);
  46.  
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement