Skip to content

Instantly share code, notes, and snippets.

@Arxero
Last active February 9, 2019 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arxero/ecc2d7f9eefe4031edff069472a69ad9 to your computer and use it in GitHub Desktop.
Save Arxero/ecc2d7f9eefe4031edff069472a69ad9 to your computer and use it in GitHub Desktop.
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