Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- function tseamAccount(arr) {
- let i = 1;
- let command = arr[i].split(' ')[0];
- //Convert gaming account into an array;
- let gamingAccountArray = arr[0].split(' ');
- while (command != 'Play!') {
- let currentGame = arr[i].split(' ')[1]
- if (command == 'Install') {
- //If the game is not installed, add it to the account;
- if ( !(gamingAccountArray.includes(currentGame)) ) gamingAccountArray.push(currentGame);
- }
- if (command == 'Uninstall') {
- //If the game is installed, remove it from the account;
- if (gamingAccountArray.includes(currentGame)) {
- removeSingleItem(gamingAccountArray, currentGame);
- }
- }
- if (command == 'Update') {
- //If the game is installed, move it from its' place to the last;
- if (gamingAccountArray.includes(currentGame)) {
- removeSingleItem(gamingAccountArray, currentGame);
- gamingAccountArray.push(currentGame);
- }
- }
- if (command == 'Expansion') {
- //Separate game name from expansion name;
- let game = currentGame.split('-')[0];
- let expansion = currentGame.split('-')[1];
- if (gamingAccountArray.includes(game)) {
- //Modify game name;
- let newGameName = game + ':' + expansion;
- //Insert expansion;
- swapItems(gamingAccountArray, game, newGameName);
- }
- }
- i++;
- //Get current game and a command;
- command = arr[i].split(' ')[0];
- }
- console.log( gamingAccountArray.join(' ') );
- //Declarations
- function removeSingleItem(arr, value) {
- let index = arr.indexOf(value);
- if (index > -1) {
- arr.splice(index, 1);
- }
- return arr;
- }
- function swapItems(arr, swappedItem, newItem) {
- let index = arr.indexOf(swappedItem);
- if (index > -1) {
- arr.splice(index, 1, newItem);
- }
- return arr;
- }
- }
- tseamAccount([
- 'CS WoW Diablo',
- 'Install LoL',
- 'Uninstall WoW',
- 'Update Diablo',
- 'Expansion CS-Go',
- 'Play!'
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement