Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Poker(input){
- let cards = input.shift();
- let InputCards = cards.split(":");
- let command = input.shift();
- let OurDeck=[];
- while(command !== 'Ready'){
- if(command.includes('Add')){
- let arrCommand = command.split(" ");
- let CardNameNew = arrCommand[1];
- if(InputCards.includes(CardNameNew)){
- OurDeck.push(CardNameNew);
- }else{
- console.log('Card not found.');
- }
- command = input.shift();
- }else if(command.includes('Insert')){
- let arrCommand = command.split(" ");
- let CardNameNew = arrCommand[1];
- let CardIndex = +arrCommand[2];
- if(InputCards.includes(CardNameNew)){
- OurDeck.splice(CardIndex, 0, CardNameNew)
- }else{
- console.log('Error!');
- }
- command = input.shift();
- }else if(command.includes('Remove')){
- let arrCommand = command.split(" ");
- let CardNameNew = arrCommand[1];
- if(OurDeck.includes(CardNameNew)){
- const isVal = (element) => element === CardNameNew;
- let indexRemove = OurDeck.findIndex(isVal);
- OurDeck.splice(indexRemove, 1);
- }else{
- console.log('Card not found.');
- }
- command = input.shift();
- }else if(command.includes('Swap')){
- let arrCommand = command.split(" ");
- let CardName1 = arrCommand[1];
- let CardName2 = arrCommand[2];
- const isCardName1 = (element) => element === CardName1;
- const isCardName2 = (element) => element === CardName2;
- let indexCardName1 = OurDeck.findIndex(isCardName1);
- let indexCardName2 = OurDeck.findIndex(isCardName2);
- OurDeck.splice(indexCardName1, 1, CardName2);
- OurDeck.splice(indexCardName2, 1, CardName1);
- command = input.shift();
- }else if(command.includes('Shuffle')){
- OurDeck = OurDeck.reverse();
- command = input.shift();
- }
- }
- console.log(OurDeck.join(' '));
- }
- Poker([
- 'Wrath:Pounce:Lifeweaver:Exodia:Aso:Pop',
- 'Add Pop',
- 'Add Exodia',
- 'Add Aso',
- 'Remove Wrath',
- 'Add SineokBqlDrakon',
- 'Shuffle deck',
- 'Insert Pesho 0',
- 'Ready'
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement