desislava_topuzakova

04. Train The Trainers

Apr 10th, 2021
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. function solve(input) {
  2. let n = Number(input[0]);
  3.  
  4. let index = 1;
  5. let name = input[index];
  6.  
  7. let totalAvg = 0;
  8. let countOfProblems = 0;
  9.  
  10. while (name != "Finish") {
  11. countOfProblems++;
  12. let avgGrade = 0;
  13. for (let i = 0; i < n; i++) {
  14. let grade = Number(input[++index]);
  15. avgGrade += grade;
  16. }
  17.  
  18. avgGrade /= n;
  19. totalAvg += avgGrade;
  20. console.log(`${name} - ${avgGrade.toFixed(2)}.`);
  21.  
  22. name = input[++index];
  23. }
  24.  
  25. console.log(`Student's final assessment is ${(totalAvg / countOfProblems).toFixed(2)}.`)
  26. }
Advertisement
Add Comment
Please, Sign In to add comment