DimiPetrov

PB - Football Tournament

Jun 4th, 2020
72
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let team = input.shift();
  3.     let sumGames = Number(input.shift());
  4.     let gameType = input.shift();
  5.  
  6.     if(sumGames = 0) {
  7.         console.log(`${team} hasn't played any games during this season.`);
  8.    } else {
  9.        for(let i = 1; i <= sumGames; i++) {
  10.            let wins = 0;
  11.            let draws = 0;
  12.            let losses = 0;
  13.            let points = 0;
  14.            switch(gameType) {
  15.                case 'W': wins++; points += 3; break;
  16.                case 'D': draws++; points += 1; break;
  17.                case 'L': losses++; break;
  18.            }
  19.            gameType = input.shift();
  20.            let percentWins = (wins / sumGames * 100).toFixed(2);
  21.        }
  22.        
  23.  
  24.        console.log(`${team} has won ${points} points during this season`);
  25.        console.log(`Total stats:`);
  26.        console.log(`## W: ${wins}`);
  27.        console.log(`## D: ${draws}`);
  28.        console.log(`## L: ${losses}`);
  29.        console.log(`Win rate: ${percentWins}%`);
  30.    }
  31.  
  32. }
RAW Paste Data