-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparagraphs.js
More file actions
39 lines (30 loc) · 928 Bytes
/
Copy pathparagraphs.js
File metadata and controls
39 lines (30 loc) · 928 Bytes
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
const { sentences } = require('./sentences');
const _DEFAULT_SENTENCES_MIN = 5;
const _DEFAULT_SENTENCES_MAX = 8;
const _MAX_PARAGRAPHS = 50;
const _sentencesInParagraph = () => {
const maxVariance = _DEFAULT_SENTENCES_MAX - _DEFAULT_SENTENCES_MIN;
const randVariance = Math.round((Math.random() * maxVariance));
const paragraphLen = _DEFAULT_SENTENCES_MIN + randVariance;
return paragraphLen;
};
const _createParagraph = () => {
const nbrSentences = _sentencesInParagraph();
let paragraph = sentences(nbrSentences);
return paragraph;
};
const _paragraph = () => {
return _createParagraph();
};
const _paragraphs = (nbr = 1) => {
const res = [];
const totalParagraphs = (( 0 < nbr ) && ( nbr <= _MAX_PARAGRAPHS )) ? nbr : 1;
for (let i = 0; i < totalParagraphs; i++) {
res.push(_createParagraph());
}
return res;
};
module.exports = {
paragraph: _paragraph,
paragraphs: _paragraphs
};