-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
44 lines (40 loc) · 1.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* @typedef Counts
* Counts from input document.
* @property {number} sentence
* Number of sentences.
* @property {number} word
* Number of words.
* @property {number} syllable
* Number of syllables.
*/
/**
* @typedef {Counts} FleschKincaidCounts
* Deprecated: please use the `Counts` type instead.
*/
const sentenceWeight = 0.39
const wordWeight = 11.8
const adjustment = 15.59
/**
* Given an object containing the number of words (`word`), the number of
* sentences (`sentence`), and the number of syllables (`syllable`) in a
* document, returns the U.S. grade level associated with the document.
*
* @param {Counts} counts
* Counts from input document.
* @returns {number}
* Grade level associated with the document.
*
* > 👉 **Note**: values can theoretically start at `-3.40` and end at
* > `Infinity`.
*/
export function fleschKincaid(counts) {
if (!counts || !counts.sentence || !counts.word || !counts.syllable) {
return Number.NaN
}
return (
sentenceWeight * (counts.word / counts.sentence) +
wordWeight * (counts.syllable / counts.word) -
adjustment
)
}