Guest User

Untitled

a guest
Jun 4th, 2020
53
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2.   let playerOne = input.shift();
  3.   let playerTwo = input.shift();
  4.  
  5.   let command = input.shift();
  6.  
  7.   let pointsPlayerOne = 0;
  8.   let pointsPlayerTwo = 0;
  9.  
  10.   while (command !== "End of game"){
  11.     let cardPlayerOne = +command;
  12.     let cardPlayerTwo = +input.shift();
  13.  
  14.     if(cardPlayerOne > cardPlayerTwo){
  15.       pointsPlayerOne += cardPlayerOne - cardPlayerTwo;
  16.     } else if(cardPlayerOne < cardPlayerTwo){
  17.       pointsPlayerTwo += cardPlayerTwo - cardPlayerOne;
  18.     } else {
  19.       console.log(`Number wars!`);
  20.  
  21.       cardPlayerOne = +input.shift();
  22.       cardPlayerTwo = +input.shift();
  23.  
  24.       if(cardPlayerOne > cardPlayerTwo){
  25.         console.log(`${playerOne} is winner with ${pointsPlayerOne} points`);
  26.         return;
  27.       } else if(cardPlayerOne < cardPlayerTwo) {
  28.         console.log(`${playerTwo} is winner with ${pointsPlayerTwo} points`);
  29.         return;
  30.       }
  31.     }
  32.  
  33.     command = input.shift();
  34.   }
  35.  
  36.   if(command === 'End of game') {
  37.     console.log(`${playerOne} has ${pointsPlayerOne} points`);
  38.     console.log(`${playerTwo} has ${pointsPlayerTwo} points`);
  39.   }
  40. }
RAW Paste Data