Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tennisRanklist(input) {
- let tournamentsNumber = Number(input.shift());
- let startPointsNumberInRanklist = Number(input.shift());
- let points = 0;
- let allPoints = 0;
- let winnerCounter = 0;
- let stageInTournament = input.shift();
- for (let i = 1; i <= tournamentsNumber; i++) {
- let startingPoints = startPointsNumberInRanklist;
- if (stageInTournament == 'W') {
- points = 2000;
- winnerCounter++;
- } else if (stageInTournament == 'F') {
- points = 1200;
- } else if (stageInTournament == 'SF') {
- points = 720;
- }
- allPoints += startPointsNumberInRanklist + points;
- stageInTournament = input.shift();
- }
- let averagePoints = allPoints / tournamentsNumber;
- let winnerPercent = winnerCounter / tournamentsNumber * 100;
- console.log(`Final points: ${allPoints}`);
- console.log(`Average points: ${averagePoints}`);
- console.log(`${winnerPercent.toFixed(2)}%`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement