Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 = ''
- if (inputLine[1] != undefined) {
- game = inputLine[1]
- }
- switch (command) {
- case 'Install':
- if (!games.includes(game)) {
- games.push(game)
- }
- break;
- case 'Uninstall':
- let currentGameIndexUninstall = 0
- for (let j = 0; j < games.length; j++) {
- if (games[j] == game) {
- currentGameIndexUninstall = j
- }
- }
- if (games.includes(game)) {
- games.splice(currentGameIndexUninstall, 1)
- }
- break;
- case 'Update':
- let currentGameIndexUpdate = 0
- if (games.includes(game)) {
- for (let k = 0; k < games.length; k++) {
- if (games[k] == game) {
- currentGameIndexUpdate = k
- }
- }
- games.splice(currentGameIndexUpdate, 1)
- games.push(game)
- }
- break;
- case 'Expansion':
- game = game.split('-')
- let theExpansion = game[0] + ':' + game[1]
- if (games.includes(game[0])) {
- let currentGameIndexExpansion = 0
- for (let l = 0; l < games.length; l++) {
- if (games[l] == game[0]) {
- currentGameIndexExpansion = l
- }
- }
- games.splice(currentGameIndexExpansion + 1, 0, theExpansion)
- }
- break;
- }
- }
- console.log(games.join(' '))
- }
- // solution('CS WoW Diablo')
- // solution('Install LoL')
- // solution('Uninstall WoW')
- // solution( 'Update Diablo')
- // solution('Expansion CS-Go')
- // solution('Play!')
- solution(
- 'CS WoW Diablo',
- 'Install LoL',
- 'Uninstall WoW',
- 'Update Diablo',
- 'Expansion CS-Go',
- 'Play!'
- )
- // solution(
- // 'CS WoW Diablo',
- // 'Uninstall XCOM',
- // 'Update PeshoGame',
- // 'Update WoW',
- // 'Expansion Civ-V',
- // 'Play!'
- // )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement