Advertisement
Guest User

05."Tennis Ranklist" from Softuni - 9/10 March 2019 Exam

a guest
Apr 2nd, 2019
1,599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tennisRanklist(input) {
  2.     let tournamentsNumber = Number(input.shift());
  3.     let allPoints = Number(input.shift());
  4.     let currentPoints = 0;
  5.     let points = 0;
  6.     let winnerCounter = 0;
  7.     let stageInTournament = input.shift();
  8.  
  9.     for (let i = 1; i <= tournamentsNumber; i++) {  
  10.         if (stageInTournament == 'W') {
  11.             points = 2000;
  12.             winnerCounter++;
  13.         } else if (stageInTournament == 'F') {
  14.             points = 1200;
  15.         } else if (stageInTournament == 'SF') {
  16.             points = 720;
  17.         }
  18.         allPoints += points;
  19.         currentPoints += points;
  20.         stageInTournament = input.shift();
  21.     }
  22.     let averagePoints = currentPoints / tournamentsNumber;
  23.     let winnerPercent = winnerCounter / tournamentsNumber * 100;
  24.     console.log(`Final points: ${allPoints}`);
  25.     console.log(`Average points: ${Math.floor(averagePoints)}`);
  26.     console.log(`${winnerPercent.toFixed(2)}%`);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement