Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
poker-hands
Advanced tools
Readme
Quickly evaluate poker hands.
In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the following way:
- High Card: Highest value card.
- One Pair: Two cards of the same value.
- Two Pairs: Two different pairs.
- Three of a Kind: Three cards of the same value.
- Straight: All cards are consecutive values.
- Flush: All cards of the same suit.
- Full House: Three of a kind and a pair.
- Four of a Kind: Four cards of the same value.
- Straight Flush: All cards are consecutive values of same suit.
- Royal Flush: Ten, Jack, Queen, King, Ace, in same suit.
The cards are valued in the order:
- 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace.
$ npm install poker-hands
var poker = require('poker-hands');
A hand is represented as a string of 5 pairs of characters. For example:
'5H 5C 6S 7S KD' // is a hand with
// 5 of Hearts
// 5 of Clubs
// 6 of Spades
// 7 of Spades
// King of Diamonds
'2C 3S 8S 8D TD' // is a hand with
// 2 of Clubs
// 3 of Spades
// 8 of Spades
// 8 of Diamonds
// Ten of Diamonds
Given a tuple of two hands, return the index of the stronger hand.
poker.judgeWinner(['5H 5C 6S 7S KD', '2C 3S 8S 8D TD']); // 1
poker.judgeWinner(['5D 8C 9S JS AC', '2C 5C 7D 8S QH']); // 0
poker.judgeWinner(['2D 9C AS AH AC', '3D 6D 7D TD QD']); // 1
poker.judgeWinner(['4D 6S 9H QH QC', '3D 6D 7H QD QS']); // 0
poker.judgeWinner(['2H 2D 4C 4D 4S', '3C 3D 3S 9S 9D']); // 0
Return an array of the cards' values, sorted strongest to weakest.
poker.highestCards('5D AC JS 8C 9S'); // ['A', 'J', '9', '8', '5']
poker.highestCards('2C 5C 7D 8S QH'); // ['Q', '8', '7', '5', '2']
If the hand has a pair, return the value of the pair, otherwise return undefined
.
poker.hasPair('5H 5C 6S 7S KD'); // '5'
poker.hasPair('2C 3S 8S 8D TD'); // '8'
poker.hasPair('2C 5C 7D 8S QH'); // undefined
If the hand has a two pairs, return an array of the values of the pairs with the strongest first, otherwise return undefined
.
poker.hasTwoPair('3H 9C 9S 2D 3D'); // ['9', '3']
poker.hasTwoPair('7S 8H 8C KH KS'); // ['K', '8']
poker.hasTwoPair('5H 5C 6S 7S KD'); // undefined
If the hand has a three of a kind, return the value of the three of a kind, otherwise return undefined
.
poker.hasThreeOfAKind('3H 9C 9S 2D 9D'); // '9'
poker.hasThreeOfAKind('7S 8H 8C KH KS'); // undefined
If the hand has a straight, return the highest value in the straight, otherwise return undefined
.
poker.hasStraight('8D 6C 5S 7H 4S'); // '8'
poker.hasStraight('7S 8H 8C KH KS'); // undefined
If the hand has a flush, return the suit of the flush, otherwise return undefined
.
poker.hasFlush('3D 6D 7D TD QD'); // 'D'
poker.hasFlush('7S 8H 8C KH KS'); // undefined
If the hand has a full house, return the value of the three of a kind, otherwise return undefined
.
poker.hasFullHouse('2H 2D 4C 4D 4S'); // '4'
poker.hasFullHouse('3C 3D 3S 9S 9D'); // '3'
If the hand has a four of a kind, return the value of the four of a kind, otherwise return undefined
.
poker.hasFourOfAKind('9D 9S KH 9H 9C'); // '9'
poker.hasFourOfAKind('3H 7C 7S 2D 7D'); // undefined
If the hand has a straight flush, return the highest value in the straight, otherwise return undefined
.
poker.hasStraightFlush('4H 3H 6H 5H 7H'); // '7'
poker.hasStraightFlush('9D 9S KH 9H 9C'); // undefined
Return a boolean for if the hand has a royal flush.
poker.hasRoyalFlush('AD KD JD QD TD'); // true
poker.hasRoyalFlush('4D 7D KD QD 2D'); // false
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test
FAQs
Quickly evaluate poker hands
The npm package poker-hands receives a total of 2 weekly downloads. As such, poker-hands popularity was classified as not popular.
We found that poker-hands demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.