Last active
February 9, 2019 09:59
-
-
Save Arxero/ecc2d7f9eefe4031edff069472a69ad9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function solution(input) { | |
let games = input[0].split(' ') | |
for (let i = 1; i < input.length; i++) { | |
let inputLine = input[i].split(' ') | |
let command = inputLine[0] | |
let game = inputLine[1] | |
let expansion = '' | |
if (command == 'Expansion') { | |
let gameWithExpansion = game.split('-') | |
game = gameWithExpansion[0] | |
expansion = game + ':' + gameWithExpansion[1] | |
} | |
let indexOfGame = games.indexOf(game) | |
switch (command) { | |
case 'Install': | |
if (!games.includes(game)) { | |
games.push(game) | |
} | |
break; | |
case 'Uninstall': | |
if (games.includes(game)) { | |
games.splice(indexOfGame, 1) | |
} | |
break; | |
case 'Update': | |
if (games.includes(game)) { | |
games.splice(indexOfGame, 1) | |
games.push(game) | |
} | |
break; | |
case 'Expansion': | |
if (games.includes(game)) { | |
games.splice(indexOfGame + 1, 0, expansion) | |
} | |
break; | |
} | |
} | |
console.log(games.join(' ')) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment