Advertisement
Btwonu

Steam

Jun 14th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. function tseamAccount(arr) {
  4.  
  5.   let i = 1;
  6.   let command = arr[i].split(' ')[0];
  7.  
  8.   //Convert gaming account into an array;
  9.   let gamingAccountArray = arr[0].split(' ');
  10.  
  11.   while (command != 'Play!') {
  12.     let currentGame = arr[i].split(' ')[1]
  13.  
  14.     if (command == 'Install') {
  15.       //If the game is not installed, add it to the account;
  16.       if ( !(gamingAccountArray.includes(currentGame)) ) gamingAccountArray.push(currentGame);
  17.     }
  18.  
  19.     if (command == 'Uninstall') {
  20.       //If the game is installed, remove it from the account;
  21.       if (gamingAccountArray.includes(currentGame)) {
  22.         removeSingleItem(gamingAccountArray, currentGame);
  23.       }
  24.     }
  25.  
  26.     if (command == 'Update') {
  27.       //If the game is installed, move it from its' place to the last;
  28.       if (gamingAccountArray.includes(currentGame)) {
  29.         removeSingleItem(gamingAccountArray, currentGame);
  30.         gamingAccountArray.push(currentGame);
  31.       }
  32.     }
  33.  
  34.     if (command == 'Expansion') {
  35.       //Separate game name from expansion name;
  36.       let game = currentGame.split('-')[0];
  37.       let expansion = currentGame.split('-')[1];
  38.       if (gamingAccountArray.includes(game)) {
  39.         //Modify game name;
  40.         let newGameName = game + ':' + expansion;
  41.         //Insert expansion;
  42.         swapItems(gamingAccountArray, game, newGameName);
  43.       }
  44.     }
  45.  
  46.     i++;
  47.     //Get current game and a command;
  48.     command = arr[i].split(' ')[0];
  49.   }
  50.  
  51.   console.log( gamingAccountArray.join(' ') );
  52.  
  53.   //Declarations
  54.   function removeSingleItem(arr, value) {
  55.     let index = arr.indexOf(value);
  56.  
  57.     if (index > -1) {
  58.       arr.splice(index, 1);
  59.     }
  60.     return arr;
  61.   }
  62.  
  63.   function swapItems(arr, swappedItem, newItem) {
  64.     let index = arr.indexOf(swappedItem);
  65.  
  66.     if (index > -1) {
  67.       arr.splice(index, 1, newItem);
  68.     }
  69.     return arr;
  70.   }
  71. }
  72.  
  73. tseamAccount([
  74.   'CS WoW Diablo',
  75.   'Install LoL',
  76.   'Uninstall WoW',
  77.   'Update Diablo',
  78.   'Expansion CS-Go',
  79.   'Play!'
  80. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement