Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let account = input.shift().split(' ');
- for (let line of input) {
- if (line === 'Play') {
- break;
- }
- let [command, game] = line.split(' ')
- if (command === 'Install') {
- if (!account.includes(game)) {
- account.push(game);
- }
- } else if (command === 'Uninstall') {
- if (account.includes(game)) {
- let index = account.indexOf(game);
- account.splice(index, 1);
- }
- } else if (command === 'Update') {
- if (account.includes(game)) {
- let index = account.indexOf(game);
- account.splice(index, 1);
- account.push(game);
- }
- } else if (command === 'Expansion') {
- game = game.split('-');
- let expansion = game[1];
- let originalGame = game[0];
- let index = account.indexOf(originalGame);
- if (account.includes(originalGame)) {
- account.splice(index + 1, 0, originalGame + ':' + expansion);
- }
- }
- }
- console.log(account.join(' '));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement