-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
74 lines (64 loc) · 1.68 KB
/
test.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import Card from './Card.js';
import { getHandString } from './pokerHand.js';
import { Ace, Three, Four, Five, Six, Two, King, Queen, Jack, Ten } from './ranks.js';
import { Clubs, Diamonds, Hearts, Spades } from './suits.js';
const straight = [
new Card(Ace, Clubs),
new Card(Two, Diamonds),
new Card(Three, Hearts),
new Card(Four, Clubs),
new Card(Five, Spades)
];
const broadway = [
new Card(Ace, Clubs),
new Card(King, Diamonds),
new Card(Queen, Hearts),
new Card(Jack, Clubs),
new Card(Ten, Spades)
];
const flush = [
new Card(Ace, Clubs),
new Card(Six, Clubs),
new Card(Queen, Clubs),
new Card(Jack, Clubs),
new Card(Ten, Clubs)
];
const royal = [
new Card(Ace, Diamonds),
new Card(King, Diamonds),
new Card(Queen, Diamonds),
new Card(Jack, Diamonds),
new Card(Ten, Diamonds)
];
const straightFlush = [
new Card(Six, Hearts),
new Card(Two, Hearts),
new Card(Three, Hearts),
new Card(Four, Hearts),
new Card(Five, Hearts)
];
const steelWheel = [
new Card(Ace, Hearts),
new Card(Two, Hearts),
new Card(Three, Hearts),
new Card(Four, Hearts),
new Card(Five, Hearts)
];
const fullHouse = [
new Card(Jack, Hearts),
new Card(Six, Hearts),
new Card(Jack, Diamonds),
new Card(Jack, Clubs),
new Card(Six, Clubs)
];
const getShortHandName = (hand) =>
hand.sort((first,second) => second.rank - first.rank)
.map((card) => card.toString()).join();
const output = (hand) => `${getShortHandName(hand)} ${getHandString(hand)}`;
console.log(output(straight));
console.log(output(broadway));
console.log(output(flush));
console.log(output(royal));
console.log(output(straightFlush));
console.log(output(steelWheel));
console.log(output(fullHouse));