Reference · Sentence difficulty
sentenceDifficultyfunction
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 it
import { sentenceDifficulty } from "@johnmorrisdotca/hikidashi/difficulty";
Also exported from: @johnmorrisdotca/hikidashi
Definition
function sentenceDifficulty(text: string, costs: ReadonlyMap<string, number>): number
Parameters
| Name | Type | Description |
|---|---|---|
text | string | The sentence. |
costs | ReadonlyMap<string, number> | Each kanji's cost, from |
Returns
number
The score: the number of characters plus three times the cost of the hardest kanji. Lower is easier.
Examples
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 66What it prints (run when this page was built)