sortedHandfunction
A hand sorted by suit (the fresh-deck order) and then by rank: how a player arranges one.
Import it
import { sortedHand } from "@johnmorrisdotca/toranpu/deck";
Definition
function sortedHand(cards: readonly Card[], rankOrder?: (rank: Rank) => number, suitOrder?: readonly Suit[]): Card[]
Parameters
| Name | Type | Description |
|---|---|---|
cards | readonly Card[] | The cards in their current order. |
rankOrder (optional) | (rank: Rank) => number | A function that gives each rank its sorting value. |
suitOrder (optional) | readonly Suit[] | The suit order for sorting a hand. |
Returns
Card[]
A hand sorted by suit (the fresh-deck order) and then by rank: how a player arranges one.
Examples
import { shuffledDeck, sortedHand } from "@johnmorrisdotca/toranpu/deck";
console.log(sortedHand(shuffledDeck(42).slice(0, 7)));[
{ suit: 'spades', rank: 7 },
{ suit: 'hearts', rank: 2 },
{ suit: 'hearts', rank: 13 },
{ suit: 'diamonds', rank: 9 },
{ suit: 'clubs', rank: 3 },
{ suit: 'clubs', rank: 9 },
{ suit: 'clubs', rank: 13 }
]What it prints (run when this page was built)