Advertisement
dabidabidesh

Untitled

Jun 10th, 2020
2,410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(array) {
  2.  
  3.   let newArray = array[0].split(' ');
  4.   let currentAction = [];
  5.   let game = '';
  6.   let expansion = '';
  7.   let gameExpansion = '';
  8.   let expansionArray = [];
  9.  
  10.  
  11.   for (let i = 1; i < array.length; i++) {
  12.  
  13.     currentAction = array[i].split(' ');
  14.  
  15.  
  16.     if (currentAction.includes('Install')) {
  17.       //newArray.push(currentAction[1]);
  18.       array[i] = array[i].replace('Install ', '')
  19.       if (!newArray.includes(array[i]))
  20.         newArray = newArray.concat('' + array[i])
  21.     }
  22.  
  23.     if (currentAction.includes('Uninstall')) {
  24.       game = currentAction[1];
  25.       for (let j = 0; j < newArray.length; j++) {
  26.         if (newArray[j] === game) {
  27.           newArray.splice(j, 1);
  28.           //break;
  29.         }
  30.       }
  31.     }
  32.  
  33.     if (currentAction.includes('Update')) {
  34.       game = currentAction[1];
  35.       for (let j = 0; j < newArray.length; j++) {
  36.         if (newArray[j] === game) {
  37.           newArray.push(newArray.splice(j, 1)[0]);
  38.          // break;
  39.         }
  40.       }
  41.     }
  42.  
  43.     if (currentAction.includes('Expansion')) {
  44.       expansionArray = currentAction[1].split('-')
  45.       game = expansionArray[0];
  46.       expansion = expansionArray[1];
  47.       gameExpansion = `${game}:${expansion}`;
  48.       if (newArray.includes(game)) {
  49.         for (let k = 0; k < newArray.length; k++) {
  50.           if (game == newArray[k]) {
  51.             newArray.splice(k + 1, 0, gameExpansion);
  52.             //break;
  53.           }
  54.         }
  55.       }
  56.     }
  57.  
  58.   }
  59.   console.log(newArray.join(' '));
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement