Advertisement
PowerCell46

Tseam account JS

Dec 7th, 2022
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tseamAccount(array) {
  2.     let index = 0;
  3.     let accountArray = (array[index]).split(" ");
  4.     index++;
  5.     let currentInput = array[index];
  6.     let command = "";
  7.     let game = "";
  8.  
  9.     while (currentInput !== "Play!") {
  10.         currentInput = currentInput.split(" ");
  11.         command = currentInput.shift();
  12.         game = currentInput.shift();
  13.  
  14.         switch (command) {
  15.             case "Install":
  16.                 if (!accountArray.includes(game)) {
  17.                     accountArray.push(game);
  18.                 } break;
  19.             case "Uninstall":
  20.                 if (accountArray.includes(game)) {
  21.                     let indexOfDeletion = accountArray.indexOf(game);
  22.                     accountArray.splice(indexOfDeletion, 1);
  23.                 } break;
  24.             case "Update":
  25.                 if (accountArray.includes(game)) {
  26.                     let updateIndex = accountArray.indexOf(game);
  27.                     accountArray.splice(updateIndex, 1);
  28.                     accountArray.push(game);
  29.                 } break;
  30.             case "Expansion":
  31.                 let expansionArray = game.split("-");
  32.                 if (accountArray.includes(expansionArray[0])) {
  33.                     let indexOfExpansion = accountArray.indexOf(expansionArray[0]);
  34.                     let expansionPrint = expansionArray[0] + ":" + expansionArray[1];
  35.                     accountArray.splice(indexOfExpansion + 1, 0, expansionPrint);
  36.                 } break;
  37.         }
  38.         index++;
  39.         currentInput = array[index];
  40.     }
  41.  
  42.     console.log(accountArray.join(" "));
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement