-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
43 lines (39 loc) · 1.18 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
/**
* @typedef Counts
* Counts from input document.
* @property {number} sentence
* Number of sentences.
* @property {number} word
* Number of words.
* @property {number} [complexPolysillabicWord=0]
* Number of words that consist of three or more syllables, that are jargon,
* proper nouns, or compound words.
*/
/**
* @typedef {Counts} GunningFogCounts
* Deprecated: please use the `Counts` type instead.
*/
const complexWordWeight = 100
const weight = 0.4
/**
* Given an object containing the number of words (`word`), the number of
* sentences (`sentence`), and the number of complex (i.e., jargon, proper
* nouns, compound words) polysillabic (three or more syllables) words
* (`complexPolysillabicWord`) in a document, returns the grade level
* associated with the document.
*
* @param {Counts} counts
* Counts from input document.
* @returns {number}
* Grade level associated with the document.
*/
export function gunningFog(counts) {
if (!counts || !counts.sentence || !counts.word) {
return Number.NaN
}
return (
weight *
(counts.word / counts.sentence +
complexWordWeight * ((counts.complexPolysillabicWord || 0) / counts.word))
)
}