Skip to the content

Toranpuトランプ

Use a deck, play eleven games with computers, solve a solitaire, or display cards in your own design.

Toranpu is Japanese for playing cards. About the name

Contents

Reference · Deck tools

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

NameTypeDescription
cardsreadonly 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)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/toranpu 2.15.0.