Skip to main content

compareBestHands

Compare best 1–7 card lists; returns -1 / 0 / 1. Throws on overlap or invalid cards (unless assumeDisjoint: true).

compareBestHands(cardsA: CardInput, cardsB: CardInput, options?: CompareBestHandsOptions): number

Import

const poker = require('poker-calculations');

When to use

Use for showdown ordering when each side may have a different number of known cards (partial boards).

How to use

const cmp = poker.compareBestHands(
['Ah', 'Kh', 'Qh', 'Jh', 'Th'],
['As', 'Ks', 'Qs', 'Js', '9h'],
);
// cmp < 0 → first hand wins; 0 → tie; > 0 → second wins

Both sides accept CardInput (string[] or packed Uint8Array). See Packed card input.

When you know the two lists cannot share a card (e.g. pre-partitioned deck ids), pass { assumeDisjoint: true } to skip the overlap check. Within-hand duplicates are still rejected; passing overlapping hands with this flag produces incorrect results.

const cmpFast = poker.compareBestHands(packA, packB, { assumeDisjoint: true });

See also

evaluateBestHand