npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pokerhandrank

v1.0.3

Published

A simple algorithm (with JS ES6 features) to identify the win a hand has.

Downloads

16

Readme

Poker Hand Ranking

A simple algorithm (with JS ES6 features) to identify the win a hand has.

Git Repository

https://github.com/chetansu/pokerhand_rank.git

Usage

install the package using npm command

$ npm i pokerhandrank

for instantiation, you wil have to assign pokerhand rank to a variable. The only method that is exposed is checkRank. checkRank function takes in an array of 7 cards. and returns with a json response, indicating the type of win and the winning cards.

const pokerhand = require("pokerhandrank");

pokerhand.checkRank(["hearts-A", "hearts-K", "clubs-J", "diamonds-8", "hearts-J", "hearts-Q", "hearts-10"]);
pokerhand.checkRank(["hearts-7", "hearts-3", "clubs-7", "diamonds-7", "spades-7", "hearts-5", "spades-4"]);
pokerhand.checkRank(["hearts-9", "hearts-3", "clubs-4", "diamonds-8", "hearts-4", "hearts-5", "hearts-2"]);
pokerhand.checkRank(["hearts-4", "hearts-3", "clubs-4", "diamonds-4", "hearts-7", "clubs-5", "spades-5"]);
pokerhand.checkRank(["hearts-5", "hearts-3", "clubs-4", "diamonds-2", "hearts-7", "clubs-5", "spades-5"]);
pokerhand.checkRank(["hearts-4", "hearts-3", "clubs-3", "diamonds-4", "hearts-7", "clubs-9", "spades-5"]);
pokerhand.checkRank(["hearts-4", "hearts-A", "clubs-4", "diamonds-6", "hearts-7", "clubs-9", "spades-5"]);
pokerhand.checkRank(["hearts-4", "hearts-7", "clubs-9", "diamonds-K", "hearts-J", "clubs-2", "spades-5"]);

call to checkRank will result in the json structured below

{
  wintype: 'TWO_PAIR',
  winningcards: [ 'diamonds-4', 'hearts-4', 'hearts-3', 'clubs-3' ]
}

Testing

To run the mocha test case. please install mocha and run the cases by using the command mocha.

$ npm install -g mocha
$ mocha

  Check Poker rank of various hands
Winning Cards : hearts-A,hearts-K,hearts-Q,hearts-J,hearts-10
Rank : ROYAL_FLUSH
    ✔ cards in hand are : hearts-A,hearts-K,clubs-J,diamonds-8,hearts-J,hearts-Q,hearts-10
Winning Cards : hearts-7,clubs-7,diamonds-7,spades-7
Rank : FOUR_OF_A_KIND
    ✔ cards in hand are : hearts-7,hearts-3,clubs-7,diamonds-7,spades-7,hearts-5,spades-4
Winning Cards : hearts-9,hearts-5,hearts-4,hearts-3,hearts-2
Rank : FLUSH
    ✔ cards in hand are : hearts-9,hearts-3,clubs-4,diamonds-8,hearts-4,hearts-5,hearts-2
Winning Cards : clubs-5,spades-5,hearts-4,clubs-4,diamonds-4
Rank : FULLHOUSE
    ✔ cards in hand are : hearts-4,hearts-3,clubs-4,diamonds-4,hearts-7,clubs-5,spades-5
Winning Cards : hearts-5,clubs-5,spades-5
Rank : THREE_OF_A_KIND
    ✔ cards in hand are : hearts-5,hearts-3,clubs-4,diamonds-2,hearts-7,clubs-5,spades-5
Winning Cards : diamonds-4,hearts-4,hearts-3,clubs-3
Rank : TWO_PAIR
    ✔ cards in hand are : hearts-4,hearts-3,clubs-3,diamonds-4,hearts-7,clubs-9,spades-5
Winning Cards : hearts-4,clubs-4
Rank : ONE_PAIR
    ✔ cards in hand are : hearts-4,hearts-A,clubs-4,diamonds-6,hearts-7,clubs-9,spades-5
Winning Cards : diamonds-K
Rank : HIGH_CARD
    ✔ cards in hand are : hearts-4,hearts-7,clubs-9,diamonds-K,hearts-J,clubs-2,spades-5
Winning Cards : clubs-5,spades-5,diamonds-4,hearts-4
Rank : TWO_PAIR
    ✔ cards in hand are : hearts-4,hearts-3,clubs-3,diamonds-4,hearts-7,clubs-5,spades-5
Winning Cards : clubs-5,spades-5,diamonds-4,hearts-4,clubs-4
Rank : FULLHOUSE
    ✔ cards in hand are : hearts-4,hearts-3,clubs-4,diamonds-4,clubs-3,clubs-5,spades-5
Winning Cards : hearts-5,clubs-5,spades-5,diamonds-4,hearts-4,clubs-4
Rank : FULLHOUSE
    ✔ cards in hand are : hearts-4,hearts-5,clubs-4,diamonds-4,clubs-3,clubs-5,spades-5
Winning Cards : hearts-5,diamonds-5,clubs-5,spades-5
Rank : FOUR_OF_A_KIND
    ✔ cards in hand are : hearts-4,hearts-5,clubs-4,diamonds-4,diamonds-5,clubs-5,spades-5


  12 passing (27ms)

NOTE

This library can be directly used with AWS lambda function to work as a microservice.

License

ISC Free Software, Hell Yeah!