nikolayneykov

Untitled

Feb 11th, 2019
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(commands) {
  2.   let i, j,
  3.     temp,
  4.     update,
  5.     index,
  6.     account = commands.shift().split(' ');
  7.  
  8.   for (i = 0; i < commands.length - 1; i += 1) { // length - 1, because last command is always "Play!"
  9.     temp = commands[i].split(' ');
  10.     switch (temp[0]) {
  11.       case 'Install':
  12.         if (!account.includes(temp[1])) {
  13.           account.push(temp[1]);
  14.         }
  15.         break;
  16.       case 'Uninstall':
  17.         if (account.includes(temp[1])) {
  18.           index = account.indexOf(temp[1]);
  19.           account.splice(index, 1);
  20.         }
  21.         break;
  22.       case 'Update':
  23.         if (account.includes(temp[1])) {
  24.           index = account.indexOf(temp[1]);
  25.           update = account.splice(index, 1);
  26.           account.push(update);
  27.         }
  28.         break;
  29.       case 'Expansion':
  30.         let game = temp[1].split('-')[0];
  31.         for (j = 0; j < account.length; j += 1) {
  32.           if (game === account[j]) {
  33.             //index = account.indexOf(temp[1]);
  34.             update = temp[1].replace('-', ':');
  35.             account.splice(j + 1, 0, update);
  36.             break;
  37.           }
  38.         }
  39.         break;
  40.     }
  41.   }
  42.   console.log(account.join(' '));
  43. }
  44. solve(['CS WoW Diablo',
  45.   'Install LoL',
  46.   'Uninstall WoW',
  47.   'Update Diablo',
  48.   'Expansion CS-Go',
  49.   'Play!',]
  50. );
Advertisement
Add Comment
Please, Sign In to add comment