Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function basketballTournament(input) {
- let index = 0;
- let name = input[index];
- index++;
- let allGamesCounter = 0;
- let wonGame = 0;
- let lostGame = 0;
- while (name !== "End of tournaments") {
- let matchesNumber = Number(input[index]);
- index++;
- let gamesCounter = 0;
- for (let i = 1; i <= matchesNumber; i++) {
- let hostPoints = Number(input[index]);
- index++;
- let guestPoints = Number(input[index]);
- index++;
- gamesCounter++;
- if (hostPoints > guestPoints) {
- wonGame++;
- console.log(`Game ${gamesCounter} of tournament ${name}: win with ${hostPoints - guestPoints} points.`);
- } else {
- lostGame++;
- console.log(`Game ${gamesCounter} of tournament ${name}: lost with ${guestPoints - hostPoints} points.`);
- }
- }
- allGamesCounter += gamesCounter;
- name = input[index];
- index++;
- }
- if (name === "End of tournaments") {
- console.log(`${(wonGame * 100 / allGamesCounter).toFixed(2)}% matches win`);
- console.log(`${(lostGame * 100 / allGamesCounter).toFixed(2)}% matches lost`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment