-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
41 lines (37 loc) · 1.03 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
/**
* @typedef Counts
* Counts from input document.
* @property {number} sentence
* Number of sentences.
* @property {number} word
* Number of words.
* @property {number} character
* Number of characters.
*/
/**
* @typedef {Counts} AutomatedReadabilityCounts
* Deprecated: please use the `Counts` type instead.
*/
const characterWeight = 4.71
const sentenceWeight = 0.5
const base = 21.43
/**
* Given an object containing the number of words (`word`), the number of
* sentences (`sentence`), and the number of characters (`character`) in a
* document, returns the grade level associated with the document.
*
* @param {Counts} counts
* Counts from input document.
* @return {number}
* Grade level associated with the document.
*/
export function automatedReadability(counts) {
if (!counts || !counts.sentence || !counts.word || !counts.character) {
return Number.NaN
}
return (
characterWeight * (counts.character / counts.word) +
sentenceWeight * (counts.word / counts.sentence) -
base
)
}