Advertisement
Arxero

Tseam Account

Feb 9th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution(input) {
  2.     let games = input[0].split(' ')
  3.  
  4.     for (let i = 1; i < input.length; i++) {
  5.         let inputLine = input[i].split(' ')
  6.         let command = inputLine[0]
  7.         let game = inputLine[1]
  8.         let expansion = ''
  9.        
  10.         if (command == 'Expansion') {
  11.             let gameWithExpansion = game.split('-')
  12.             game = gameWithExpansion[0]
  13.             expansion = game + ':' + gameWithExpansion[1]
  14.         }
  15.         let indexOfGame = games.indexOf(game)
  16.  
  17.         switch (command) {
  18.             case 'Install':
  19.                 if (!games.includes(game)) {
  20.                     games.push(game)
  21.                 }
  22.                 break;
  23.             case 'Uninstall':
  24.                 if (games.includes(game)) {
  25.                     games.splice(indexOfGame, 1)
  26.                 }
  27.                 break;
  28.             case 'Update':
  29.                 if (games.includes(game)) {
  30.                     games.splice(indexOfGame, 1)
  31.                     games.push(game)
  32.                 }
  33.                 break;
  34.             case 'Expansion':
  35.                 if (games.includes(game)) {
  36.                     games.splice(indexOfGame + 1, 0, expansion)
  37.                 }
  38.                 break;
  39.         }
  40.     }
  41.    
  42.     console.log(games.join(' '))
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement