Advertisement
Lulunga

final exam 03. Tseam Account only array

Aug 1st, 2019
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.  
  3.    let account = input.shift().split(' ');
  4.  
  5.    for (let line of input) {
  6.       if (line === 'Play') {
  7.          break;
  8.       }
  9.       let [command, game] = line.split(' ')
  10.       if (command === 'Install') {
  11.          if (!account.includes(game)) {
  12.             account.push(game);
  13.          }
  14.       } else if (command === 'Uninstall') {
  15.          if (account.includes(game)) {
  16.             let index = account.indexOf(game);
  17.             account.splice(index, 1);
  18.          }
  19.       } else if (command === 'Update') {
  20.          if (account.includes(game)) {
  21.             let index = account.indexOf(game);
  22.             account.splice(index, 1);
  23.             account.push(game);
  24.          }
  25.       } else if (command === 'Expansion') {
  26.  
  27.          game = game.split('-');
  28.          let expansion = game[1];
  29.          let originalGame = game[0];
  30.          let index = account.indexOf(originalGame);
  31.          if (account.includes(originalGame)) {
  32.             account.splice(index + 1, 0, originalGame + ':' + expansion);
  33.          }
  34.  
  35.  
  36.       }
  37.  
  38.    }
  39.    console.log(account.join(' '));
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement