-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
41 lines (37 loc) · 997 Bytes
/
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} [polysillabicWord]
* Number of polysillabic (three or more syllables) words.
*/
/**
* @typedef {Counts} SmogFormulaCounts
* Deprecated: please use the `Counts` type instead.
*/
const sentenceSize = 30
const weight = 1.043
const base = 3.1291
/**
* Given an object containing the number of sentences (`sentence`) and the
* number of polysillabic (three or more syllables) words (`polysillabicWord`)
* in a document, returns the reading ease associated with the document.
*
* @param {Counts} counts
* Counts from input document.
* @returns {number}
* Reading ease associated with the document.
*/
export function smogFormula(counts) {
if (!counts || !counts.sentence) {
return Number.NaN
}
return (
base +
weight *
Math.sqrt(
(counts.polysillabicWord || 0) * (sentenceSize / counts.sentence)
)
)
}