sentenceDifficulty関数
リファレンスの説明と例は英語です。見出しと目次は日本語です。
The sentence's score, lowest first: its length in characters plus three times its hardest kanji.
Kana-only sentences score their length alone, which puts them at the top where they belong: a
beginner can read every one of them. A kanji missing from costs counts as the hardest kind.
インポート
import { sentenceDifficulty } from "@johnmorrisdotca/hikidashi/difficulty";
ほかのエクスポート元: @johnmorrisdotca/hikidashi
定義
function sentenceDifficulty(text: string, costs: ReadonlyMap<string, number>): number
引数
| 名前 | 型 | 説明 |
|---|---|---|
text | string | The sentence. |
costs | ReadonlyMap<string, number> | Each kanji's cost, from |
戻り値
number
The score: the number of characters plus three times the cost of the hardest kanji. Lower is easier.
例
import { kanjiCost, sentenceDifficulty } from "@johnmorrisdotca/hikidashi/difficulty";
const costs = new Map([["水", kanjiCost({ grade: 1, frequencyRank: 223 })], ["飲", kanjiCost({ grade: 3, frequencyRank: 969 })]]);
console.log(sentenceDifficulty("みずをのむ。", costs), sentenceDifficulty("水を飲む。", costs), sentenceDifficulty("麒麟を見た。", costs));6 14 66出力(このページを作ったときに実行した結果)
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。