-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (42 loc) · 956 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const {winningPlayer, suits, ranks, hands} = require('./hands/hands-results');
function createDeck() {
return ranks
.map(rank => suits.map(suit => `${rank}${suit}`))
.reduce((acc, val) => acc.concat(val), []);
}
function pickRandomCard(deck) {
const card = deck.splice(Math.floor(Math.random() * deck.length), 1)[0];
return {
deck,
card
};
}
function dealHand(deck) {
const card = deck.splice(Math.floor(Math.random() * deck.length), 1)[0];
const card2 = deck.splice(Math.floor(Math.random() * deck.length), 1)[0];
return {
deck,
hand: [card, card2]
};
}
function dealSeven(deck) {
// simulate hand + 5 on table
const cards = [];
for (let i = 0; i < 7; i += 1) {
cards.push(deck.splice(Math.floor(Math.random() * deck.length), 1)[0]);
}
return {
deck,
cards
};
}
module.exports = {
createDeck,
pickRandomCard,
dealHand,
dealSeven,
ranks,
suits,
hands,
winningPlayer
};