Advertisement
SKGreyHound

Tseam Account

Jul 2nd, 2020
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. function tseamAccount(input) {
  2.  
  3. let games = input.shift().split(' ');
  4.  
  5. for (let i = 0; i < input.length; i++) {
  6. let [command, game] = input[i].split(' ')
  7.  
  8. switch (command) {
  9. case 'Install': install(game);
  10. break;
  11. case 'Uninstall': if (games.includes(game)) {
  12. games.splice(i, 1);
  13. }
  14. break;
  15. case 'Update': if (games.includes(game)) {
  16. update(game);
  17. }
  18. break;
  19. case 'Expansion': expansion(game);
  20. break;
  21. case 'Play!': break;
  22. }
  23. }
  24.  
  25. function install(game) {
  26. if (!games.includes(game)) {
  27. games.push(game);
  28. }
  29. return games;
  30. }
  31.  
  32. function update(game) {
  33. for (let index = 0; index < games.length; index++) {
  34. let currGame = games[index];
  35. if (currGame === game) {
  36. games.splice(index, 1);
  37. }
  38. }
  39. games.push(game);
  40. return games;
  41. }
  42.  
  43. function expansion(game) {
  44. let newGame = game.split('-');
  45. if (games.includes(newGame[0])) {
  46. let expGame = newGame.join(':');
  47. for (let index = 0; index < games.length; index++) {
  48. let currGame = games[index];
  49. if (currGame === newGame[0]) {
  50. games.splice(index + 1, 0, expGame);
  51. break;
  52. }
  53. }
  54. }
  55. return games;
  56.  
  57. }
  58. console.log(games.join(' '));
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement