tallyMedals関数
リファレンスの説明と例は英語です。見出しと目次は日本語です。
Adds up a list of medals into the rows of a table, one row for each name, keeping the first flag, mark, code and note given for it. filter keeps only the medals of one sport, one category or
one Games (or a list of them): the same list gives the table of an event, of a sport and of all time. Throws a RangeError for a medal that is not gold, silver or bronze or has no name.
インポート
import { tallyMedals } from "@johnmorrisdotca/taisen-brackets";
定義
function tallyMedals(awards: readonly MedalAward[], filter?: MedalFilter): MedalRow[]
引数
| 名前 | 型 | 説明 |
|---|---|---|
awards | readonly MedalAward[] | The medals won. |
filter (省略可) | MedalFilter | Which medals to count: a sport, a category or a Games. |
戻り値
MedalRow[]
One row for each name, ready for medalTable.
例
import { medalTable, tallyMedals } from "@johnmorrisdotca/taisen-brackets";
const awards = [
{ name: "France", flag: "FR", medal: "gold", sport: "judo", category: "+100 kg", games: 2024 },
{ name: "Japan", flag: "JP", medal: "silver", sport: "judo", category: "+100 kg", games: 2024 },
{ name: "France", medal: "bronze", sport: "judo", category: "-66 kg", games: 2020 },
{ name: "Japan", medal: "gold", sport: "wrestling", category: "-65 kg", games: 2020 },
] as const;
const judo = tallyMedals(awards, { sport: "judo" });
console.log(judo.map((r) => `${r.name} ${r.gold}-${r.silver}-${r.bronze}`).join(", "), medalTable({ rows: judo }).includes("France"));France 1-0-1, Japan 0-1-0 true出力(このページを作ったときに実行した結果)
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。