kalitarix

TseamAccount

Feb 13th, 2019
1,247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tseamAccount(input) {
  2.     let games = input[0].split(' ');
  3.  
  4.     for (let i = 1; i < input.length; i++) {
  5.         let currentEl = input[i].split(' ');
  6.         let command = currentEl[0];
  7.         let newGame = currentEl[1];
  8.  
  9.         if (command === 'Play') {
  10.             break;
  11.         } else if (command === "Install" && games.includes(newGame) === false) {
  12.             games.push(newGame);
  13.         } else if (command === 'Uninstall' && games.includes(newGame)) {
  14.             let index = games.indexOf(newGame);
  15.             games.splice(index, 1);
  16.         } else if (command === 'Update' && games.includes(newGame)) {
  17.             let index = games.indexOf(newGame);
  18.             games.splice(index, 1);
  19.             games.push(newGame);
  20.         } else if (command === 'Expansion') {
  21.             let expansion = newGame.split('-');
  22.             let game = expansion[0];
  23.  
  24.             if (games.includes(game)) {
  25.                 let expandedGame = expansion.join(':');
  26.                 let index = games.indexOf(game);
  27.                 games.splice(index + 1, 0, expandedGame);
  28.             }
  29.         }
  30.     }
  31.  
  32.     console.log(games.join(' '));
  33. }
Advertisement
Add Comment
Please, Sign In to add comment