Advertisement
Pijomir

Tseam Account

Oct 2nd, 2023 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function manageTseamAccount(input) {
  2.     let gamesAccount = input.shift().split(' ');
  3.     while(input[0] !== 'Play!') {
  4.         let [command, currentGame] = input.shift().split(' ');
  5.         switch (command) {
  6.             case 'Install': installGame(gamesAccount, currentGame); break;
  7.             case 'Uninstall': uninstallGame(gamesAccount, currentGame); break;
  8.             case 'Update': updateGame(gamesAccount, currentGame); break;
  9.             case 'Expansion':
  10.                 let [gameToBeExpanded, gameExpansion] = currentGame.split('-');
  11.                 expansionGame(gamesAccount, gameToBeExpanded, gameExpansion); break;
  12.         }
  13.     }
  14.  
  15.     function installGame(collection, game) {
  16.         if (!collection.includes(game)) {
  17.            return collection.push(game);
  18.         }
  19.     }
  20.  
  21.     function uninstallGame(collection, game) {
  22.         let gamePosition = collection.indexOf(game);
  23.         if (collection.includes(game)) {
  24.             return collection.splice(gamePosition, 1);
  25.         }
  26.     }
  27.  
  28.     function updateGame(collection, game) {
  29.         let gamePosition = collection.indexOf(game);
  30.         if (collection.includes(game)) {
  31.             let updatedGame = collection.splice(gamePosition, 1);
  32.             return collection.push(...updatedGame);
  33.         }
  34.     }
  35.  
  36.     function expansionGame(collection, game, exp) {
  37.         let gamePosition = collection.indexOf(game);
  38.         if (collection.includes(game)) {
  39.             return collection.splice(gamePosition + 1, 0, `${game}:${exp}`);
  40.         }
  41.     }
  42.  
  43.     console.log(gamesAccount.join(' '));
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement