Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(commands) {
- let i, j,
- temp,
- update,
- index,
- account = commands.shift().split(' ');
- for (i = 0; i < commands.length - 1; i += 1) { // length - 1, because last command is always "Play!"
- temp = commands[i].split(' ');
- switch (temp[0]) {
- case 'Install':
- if (!account.includes(temp[1])) {
- account.push(temp[1]);
- }
- break;
- case 'Uninstall':
- if (account.includes(temp[1])) {
- index = account.indexOf(temp[1]);
- account.splice(index, 1);
- }
- break;
- case 'Update':
- if (account.includes(temp[1])) {
- index = account.indexOf(temp[1]);
- update = account.splice(index, 1);
- account.push(update);
- }
- break;
- case 'Expansion':
- let game = temp[1].split('-')[0];
- for (j = 0; j < account.length; j += 1) {
- if (game === account[j]) {
- //index = account.indexOf(temp[1]);
- update = temp[1].replace('-', ':');
- account.splice(j + 1, 0, update);
- break;
- }
- }
- break;
- }
- }
- console.log(account.join(' '));
- }
- solve(['CS WoW Diablo',
- 'Install LoL',
- 'Uninstall WoW',
- 'Update Diablo',
- 'Expansion CS-Go',
- 'Play!',]
- );
Advertisement
Add Comment
Please, Sign In to add comment