Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - function solve(array) {
 - let newArray = array[0].split(' ');
 - let currentAction = [];
 - let game = '';
 - let expansion = '';
 - let gameExpansion = '';
 - let expansionArray = [];
 - for (let i = 1; i < array.length; i++) {
 - currentAction = array[i].split(' ');
 - if (currentAction.includes('Install')) {
 - //newArray.push(currentAction[1]);
 - array[i] = array[i].replace('Install ', '')
 - if (!newArray.includes(array[i]))
 - newArray = newArray.concat('' + array[i])
 - }
 - if (currentAction.includes('Uninstall')) {
 - game = currentAction[1];
 - for (let j = 0; j < newArray.length; j++) {
 - if (newArray[j] === game) {
 - newArray.splice(j, 1);
 - //break;
 - }
 - }
 - }
 - if (currentAction.includes('Update')) {
 - game = currentAction[1];
 - for (let j = 0; j < newArray.length; j++) {
 - if (newArray[j] === game) {
 - newArray.push(newArray.splice(j, 1)[0]);
 - // break;
 - }
 - }
 - }
 - if (currentAction.includes('Expansion')) {
 - expansionArray = currentAction[1].split('-')
 - game = expansionArray[0];
 - expansion = expansionArray[1];
 - gameExpansion = `${game}:${expansion}`;
 - if (newArray.includes(game)) {
 - for (let k = 0; k < newArray.length; k++) {
 - if (game == newArray[k]) {
 - newArray.splice(k + 1, 0, gameExpansion);
 - //break;
 - }
 - }
 - }
 - }
 - }
 - console.log(newArray.join(' '));
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment