Todorov_Stanimir

05. Tseam Account Arrays - More Exercise

Jun 1st, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tseamAccount(games) {
  2.     let listOfGames = games.shift().split(' ');
  3.     let currentOperation = games.shift();
  4.  
  5.     while (currentOperation !== 'Play!') {
  6.         let [command, game] = currentOperation.split(' ');
  7.         switch (command) {
  8.             case 'Install':
  9.                 if (!listOfGames.includes(game)) {
  10.                     listOfGames.push(game);
  11.                 }
  12.                 break;
  13.             case 'Uninstall':
  14.                 if (listOfGames.includes(game)) {
  15.                     listOfGames.splice(listOfGames.indexOf(game), 1);
  16.                 }
  17.                 break;
  18.             case 'Update':
  19.                 if (listOfGames.includes(game)) {
  20.                     listOfGames.splice(listOfGames.indexOf(game), 1);
  21.                     listOfGames.push(game);
  22.                 }
  23.                 break;
  24.             case 'Expansion':
  25.                 let [gameName, expansion] = game.split('-');
  26.                 if (listOfGames.includes(gameName)) {
  27.                     listOfGames.splice(listOfGames.indexOf(gameName) + 1, 0, `${gameName}:${expansion}`);
  28.                 }
  29.                 break;
  30.         }
  31.         currentOperation = games.shift();
  32.     }
  33.     console.log(listOfGames.join(' '));
  34. }
Advertisement
Add Comment
Please, Sign In to add comment