Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions exercises/practice/poker/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"authors": [
"lpizzinidev"
],
"contributors": [
"jagdish-15"
],
"files": {
"solution": [
"poker.js"
Expand Down
52 changes: 48 additions & 4 deletions exercises/practice/poker/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[161f485e-39c2-4012-84cf-bec0c755b66c]
description = "single hand always wins"
Expand All @@ -14,12 +21,18 @@ description = "a tie has multiple winners"
[61ed83a9-cfaa-40a5-942a-51f52f0a8725]
description = "multiple hands with the same high cards, tie compares next highest ranked, down to last card"

[da01becd-f5b0-4342-b7f3-1318191d0580]
description = "winning high card hand also has the lowest card"

[f7175a89-34ff-44de-b3d7-f6fd97d1fca4]
description = "one pair beats high card"

[e114fd41-a301-4111-a9e7-5a7f72a76561]
description = "highest pair wins"

[b3acd3a7-f9fa-4647-85ab-e0a9e07d1365]
description = "both hands have the same pair, high card wins"

[935bb4dc-a622-4400-97fa-86e7d06b1f76]
description = "two pairs beats one pair"

Expand All @@ -32,6 +45,12 @@ description = "both hands have two pairs, with the same highest ranked pair, tie
[15a7a315-0577-47a3-9981-d6cf8e6f387b]
description = "both hands have two identically ranked pairs, tie goes to remaining card (kicker)"

[f761e21b-2560-4774-a02a-b3e9366a51ce]
description = "both hands have two pairs that add to the same value, win goes to highest pair"

[fc6277ac-94ac-4078-8d39-9d441bc7a79e]
description = "two pairs first ranked by largest pair"

[21e9f1e6-2d72-49a1-a930-228e5e0195dc]
description = "three of a kind beats two pair"

Expand All @@ -40,6 +59,11 @@ description = "both hands have three of a kind, tie goes to highest ranked tripl

[eb856cc2-481c-4b0d-9835-4d75d07a5d9d]
description = "with multiple decks, two players can have same three of a kind, ties go to highest remaining cards"
include = false

[26a4a7d4-34a2-4f18-90b4-4a8dd35d2bb1]
description = "with multiple decks, two players can have same three of a kind, ties go to highest remaining cards"
reimplements = "eb856cc2-481c-4b0d-9835-4d75d07a5d9d"

[a858c5d9-2f28-48e7-9980-b7fa04060a60]
description = "a straight beats three of a kind"
Expand All @@ -50,6 +74,9 @@ description = "aces can end a straight (10 J Q K A)"
[76856b0d-35cd-49ce-a492-fe5db53abc02]
description = "aces can start a straight (A 2 3 4 5)"

[e214b7df-dcba-45d3-a2e5-342d8c46c286]
description = "aces cannot be in the middle of a straight (Q K A 2 3)"

[6980c612-bbff-4914-b17a-b044e4e69ea1]
description = "both hands with a straight, tie goes to highest ranked card"

Expand All @@ -61,6 +88,11 @@ description = "flush beats a straight"

[4d90261d-251c-49bd-a468-896bf10133de]
description = "both hands have a flush, tie goes to high card, down to the last one if necessary"
include = false

[e04137c5-c19a-4dfc-97a1-9dfe9baaa2ff]
description = "both hands have a flush, tie goes to high card, down to the last one if necessary"
reimplements = "4d90261d-251c-49bd-a468-896bf10133de"

[3a19361d-8974-455c-82e5-f7152f5dba7c]
description = "full house beats a flush"
Expand All @@ -83,5 +115,17 @@ description = "with multiple decks, both hands with identical four of a kind, ti
[923bd910-dc7b-4f7d-a330-8b42ec10a3ac]
description = "straight flush beats four of a kind"

[d9629e22-c943-460b-a951-2134d1b43346]
description = "aces can end a straight flush (10 J Q K A)"

[05d5ede9-64a5-4678-b8ae-cf4c595dc824]
description = "aces can start a straight flush (A 2 3 4 5)"

[ad655466-6d04-49e8-a50c-0043c3ac18ff]
description = "aces cannot be in the middle of a straight flush (Q K A 2 3)"

[d0927f70-5aec-43db-aed8-1cbd1b6ee9ad]
description = "both hands have straight flush, tie goes to highest-ranked card"
description = "both hands have a straight flush, tie goes to highest-ranked card"

[be620e09-0397-497b-ac37-d1d7a4464cfc]
description = "even though an ace is usually high, a 5-high straight flush is the lowest-scoring straight flush"
60 changes: 57 additions & 3 deletions exercises/practice/poker/poker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ describe('Poker', () => {
expect(bestHands(hands)).toEqual(expected);
});

xtest('winning high card hand also has the lowest card', () => {
const hands = ['2S 5H 6S 8D 7H', '3S 4D 6D 8C 7S'];
const expected = ['2S 5H 6S 8D 7H'];
expect(bestHands(hands)).toEqual(expected);
});

xtest('one pair beats high card', () => {
const hands = ['4S 5H 6C 8D KH', '2S 4H 6S 4D JH'];
const expected = ['2S 4H 6S 4D JH'];
Expand All @@ -43,6 +49,12 @@ describe('Poker', () => {
expect(bestHands(hands)).toEqual(expected);
});

xtest('both hands have the same pair, high card wins', () => {
const hands = ['4H 4S AH JC 3D', '4C 4D AS 5D 6C'];
const expected = ['4H 4S AH JC 3D'];
expect(bestHands(hands)).toEqual(expected);
});

xtest('two pairs beats one pair', () => {
const hands = ['2S 8H 6S 8D JH', '4S 5H 4C 8C 5C'];
const expected = ['4S 5H 4C 8C 5C'];
Expand All @@ -67,6 +79,18 @@ describe('Poker', () => {
expect(bestHands(hands)).toEqual(expected);
});

xtest('both hands have two pairs that add to the same value, win goes to highest pair', () => {
const hands = ['6S 6H 3S 3H AS', '7H 7S 2H 2S AC'];
const expected = ['7H 7S 2H 2S AC'];
expect(bestHands(hands)).toEqual(expected);
});

xtest('two pairs first ranked by largest pair', () => {
const hands = ['5C 2S 5S 4H 4C', '6S 2S 6H 7C 2C'];
const expected = ['6S 2S 6H 7C 2C'];
expect(bestHands(hands)).toEqual(expected);
});

xtest('three of a kind beats two pair', () => {
const hands = ['2S 8H 2H 8D JH', '4S 5H 4C 8S 4H'];
const expected = ['4S 5H 4C 8S 4H'];
Expand All @@ -80,7 +104,7 @@ describe('Poker', () => {
});

xtest('with multiple decks, two players can have same three of a kind, ties go to highest remaining cards', () => {
const hands = ['4S AH AS 7C AD', '4S AH AS 8C AD'];
const hands = ['5S AH AS 7C AD', '4S AH AS 8C AD'];
const expected = ['4S AH AS 8C AD'];
expect(bestHands(hands)).toEqual(expected);
});
Expand All @@ -103,6 +127,12 @@ describe('Poker', () => {
expect(bestHands(hands)).toEqual(expected);
});

xtest('aces cannot be in the middle of a straight (Q K A 2 3)', () => {
const hands = ['2C 3D 7H 5H 2S', 'QS KH AC 2D 3S'];
const expected = ['2C 3D 7H 5H 2S'];
expect(bestHands(hands)).toEqual(expected);
});

xtest('both hands with a straight, tie goes to highest ranked card', () => {
const hands = ['4S 6C 7S 8D 5H', '5S 7H 8S 9D 6H'];
const expected = ['5S 7H 8S 9D 6H'];
Expand All @@ -122,8 +152,8 @@ describe('Poker', () => {
});

xtest('both hands have a flush, tie goes to high card, down to the last one if necessary', () => {
const hands = ['4H 7H 8H 9H 6H', '2S 4S 5S 6S 7S'];
const expected = ['4H 7H 8H 9H 6H'];
const hands = ['2H 7H 8H 9H 6H', '3S 5S 6S 7S 8S'];
const expected = ['2H 7H 8H 9H 6H'];
expect(bestHands(hands)).toEqual(expected);
});

Expand Down Expand Up @@ -169,9 +199,33 @@ describe('Poker', () => {
expect(bestHands(hands)).toEqual(expected);
});

xtest('aces can end a straight flush (10 J Q K A)', () => {
const hands = ['KC AH AS AD AC', '10C JC QC KC AC'];
const expected = ['10C JC QC KC AC'];
expect(bestHands(hands)).toEqual(expected);
});

xtest('aces can start a straight flush (A 2 3 4 5)', () => {
const hands = ['KS AH AS AD AC', '4H AH 3H 2H 5H'];
const expected = ['4H AH 3H 2H 5H'];
expect(bestHands(hands)).toEqual(expected);
});

xtest('aces cannot be in the middle of a straight flush (Q K A 2 3)', () => {
const hands = ['2C AC QC 10C KC', 'QH KH AH 2H 3H'];
const expected = ['2C AC QC 10C KC'];
expect(bestHands(hands)).toEqual(expected);
});

xtest('both hands have straight flush, tie goes to highest-ranked card', () => {
const hands = ['4H 6H 7H 8H 5H', '5S 7S 8S 9S 6S'];
const expected = ['5S 7S 8S 9S 6S'];
expect(bestHands(hands)).toEqual(expected);
});

xtest('even though an ace is usually high, a 5-high straight flush is the lowest-scoring straight flush', () => {
const hands = ['2H 3H 4H 5H 6H', '4D AD 3D 2D 5D'];
const expected = ['2H 3H 4H 5H 6H'];
expect(bestHands(hands)).toEqual(expected);
});
});