Advertisement
Arxero

Tseam Account

Feb 8th, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution(...input) {
  2.  
  3.     let games = input[0].split(' ')
  4.  
  5.     for (let i = 1; i < input.length; i++) {
  6.         let inputLine = input[i].split(' ')
  7.         let command = inputLine[0]
  8.         let game = ''
  9.  
  10.         if (inputLine[1] != undefined) {
  11.             game = inputLine[1]
  12.         }
  13.  
  14.  
  15.         switch (command) {
  16.             case 'Install':
  17.                 if (!games.includes(game)) {
  18.                     games.push(game)
  19.                 }
  20.                 break;
  21.             case 'Uninstall':
  22.                 let currentGameIndexUninstall = 0
  23.                 for (let j = 0; j < games.length; j++) {
  24.                     if (games[j] == game) {
  25.                         currentGameIndexUninstall = j
  26.                     }
  27.                 }
  28.                 if (games.includes(game)) {
  29.                     games.splice(currentGameIndexUninstall, 1)
  30.                 }
  31.  
  32.                 break;
  33.             case 'Update':
  34.                 let currentGameIndexUpdate = 0
  35.                 if (games.includes(game)) {
  36.                     for (let k = 0; k < games.length; k++) {
  37.                         if (games[k] == game) {
  38.                             currentGameIndexUpdate = k
  39.                         }
  40.                     }
  41.                     games.splice(currentGameIndexUpdate, 1)
  42.                     games.push(game)
  43.                 }
  44.                 break;
  45.             case 'Expansion':
  46.                 game = game.split('-')
  47.                 let theExpansion = game[0] + ':' + game[1]
  48.  
  49.                 if (games.includes(game[0])) {
  50.                     let currentGameIndexExpansion = 0
  51.                     for (let l = 0; l < games.length; l++) {
  52.  
  53.                         if (games[l] == game[0]) {
  54.                             currentGameIndexExpansion = l
  55.                         }
  56.                     }
  57.                     games.splice(currentGameIndexExpansion + 1, 0, theExpansion)
  58.                 }
  59.                 break;
  60.         }
  61.     }
  62.  
  63.     console.log(games.join(' '))
  64. }
  65.  
  66.  
  67. // solution('CS WoW Diablo')
  68. // solution('Install LoL')
  69. // solution('Uninstall WoW')
  70. // solution( 'Update Diablo')
  71. // solution('Expansion CS-Go')
  72. // solution('Play!')
  73.  
  74. solution(
  75.     'CS WoW Diablo',
  76.     'Install LoL',
  77.     'Uninstall WoW',
  78.     'Update Diablo',
  79.     'Expansion CS-Go',
  80.     'Play!'
  81. )
  82.  
  83. // solution(
  84. //     'CS WoW Diablo',
  85. //     'Uninstall XCOM',
  86. //     'Update PeshoGame',
  87. //     'Update WoW',
  88. //     'Expansion Civ-V',
  89. //     'Play!'
  90. // )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement