私はJavaScriptの初心者であり、生成されたカードがすでに使用されているかどうかをスクリプトに尋ねるより良い方法があるかどうか知りたいです。
現在、私はたくさんのOr演算子を使用していますが、それを行うための冗長性の少ない方法が必要です。誰かが私の質問に答えることができれば、それは長期的には本当に私を助けてくれるでしょう。ありがとう
var cards = ['Ace of heart','Ace of club','Ace of diamond','Ace of spade',
'Two of heart','Two of club','Two of diamond','Two of spade',
'Three of heart','Three of club','Three of diamond','Three of spade',
'Four of heart','Four of club','Four of diamond','Four of spade',
'Five of heart','Five of club','Five of diamond','Five of spade'];
// Distributed Cards //
var pre_flop = [1];
var flop = [2];
var turn = [0];
var river = [0];
// Cards value //
var your_card;
var indexed_cards = [6];
var total_card = 0;
var deck_size = cards.length;
function generate_card(){
// Assign value to first card //
if(total_card === 0){
your_card = Math.floor(Math.random() * deck_size);
indexed_cards [total_card] = your_card;
total_card++;
}else{
your_card = Math.floor(Math.random() * deck_size);
// Makes sure the cards are different //
while(1){
if(your_card === indexed_cards [0] || your_card === indexed_cards [1] || your_card === indexed_cards [2] || your_card === indexed_cards [3] || your_card === indexed_cards [4] || your_card === indexed_cards [5] || your_card === indexed_cards [6]){
your_card = Math.floor(Math.random() * deck_size);
}else {
indexed_cards [total_card] = your_card;
break;
}
}
total_card++;
}
}