Advertisement
Guest User

Untitled

a guest
Aug 15th, 2021
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. function wizardPoker(array) {
  2. let deck = array.shift().split(':');
  3. let index = 0;
  4. let card = []
  5. let newDeck = []
  6.  
  7. for (let i = 0; i < array.length; i++) {
  8. let command = array[i].split(' ');
  9.  
  10. if (command[0] === 'Add') {
  11. if (deck.includes(command[1])) {
  12. index = deck.indexOf(command[1]);
  13. card = deck.splice(index, 1);
  14. newDeck.push(card[0]);
  15. } else {
  16. console.log(`Card not found.`);
  17. }
  18. } else if (command[0] === 'Insert') {
  19. if (deck.includes(command[1])) {
  20. if (Number(command[2]) >= 0 && Number(command[2]) < deck.length) {
  21. index = deck.indexOf(command[1]);
  22. card = deck.splice(index, 1);
  23. newDeck.splice(Number(command[2]), 0, card[0]);
  24. } else {
  25. console.log('Error!');
  26. }
  27. } else {
  28. console.log('Error!');
  29.  
  30. }
  31. } else if (command[0] === 'Remove') {
  32. index = newDeck.indexOf(command[1]);
  33.  
  34. if (index >= 0) {
  35. newDeck.splice(index, 1);
  36. } else {
  37. console.log(`Card not found.`);
  38.  
  39. }
  40. } else if (command[0] === 'Swap') {
  41. if (newDeck.includes(command[1]) && newDeck.includes(command[2])) {
  42. let firstCardIndex = newDeck.indexOf(command[1]);
  43. let firstCard = newDeck.splice(firstCardIndex, 1);
  44. let secondCardIndex = newDeck.indexOf(command[2]);
  45. let secondCard = newDeck.splice(secondCardIndex, 1);
  46.  
  47. newDeck.splice(secondCardIndex, 0, firstCard[0]);
  48. newDeck.splice(firstCardIndex, 0, secondCard[0]);
  49. }
  50. } else if (command[0] === 'Shuffle') {
  51. newDeck.reverse();
  52.  
  53. } else if (command[0] === 'Ready') {
  54. console.log(newDeck.join(' '));
  55. return;
  56.  
  57. }
  58. }
  59. }
  60.  
  61. wizardPoker(['Wrath:Pounce:Lifeweaver:Exodia:Aso:Pop', 'Remove Pounce', 'Add Pounce', 'Remove Pounce', 'Add Pounce', 'Add Wrath', 'Add Lifeweaver', 'Add Exodia', 'Remove Exodia', 'Remove Exodia', 'Add Exodia', 'Insert Pop 2', 'Swap Wrath Lifeweaver', 'Swap Exodia Wrath', 'Ready']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement