randomDrawIndex関数
リファレンスの説明と例は英語です。見出しと目次は日本語です。
Choose a card whose name contains the filter, avoiding the current card when another match exists.
インポート
import { randomDrawIndex } from "@johnmorrisdotca/fuda-cards/collection";
定義
function randomDrawIndex(cards: CollectionCard[], current: number, filter: string, random?: () => number): number | null
引数
| 名前 | 型 | 説明 |
|---|---|---|
cards | CollectionCard[] | The collection. |
current | number | The index of the card now on top. |
filter | string | Text the name must contain, whatever its case; spaces round it are ignored. Empty matches every card. |
random (省略可) | () => number | A source of numbers from 0 up to but not including 1. Unless said, |
戻り値
number | null
The index of the card to draw, or null when no card matches.
例
import { randomDrawIndex } from "@johnmorrisdotca/fuda-cards/collection";
const cards = ["Alpha", "Beta", "Gamma"].map((name, i) => ({ id: String(i), name, image: `${i}.jpg` }));
console.log(randomDrawIndex(cards, 0, "", () => 0)); // 1
console.log(randomDrawIndex(cards, 0, "zzz")); // null1
null出力(このページを作ったときに実行した結果)
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。