|
@@ -7,28 +7,28 @@
|
|
|
|
|
|
const defaultOptions = {
|
|
|
minWords: 3,
|
|
|
- maxWords: 9
|
|
|
+ maxWords: 9,
|
|
|
+ availableWords: require('./words'),
|
|
|
+ punctuationMarks: ['.', '!', '?']
|
|
|
};
|
|
|
|
|
|
-const availableWords = require('./words');
|
|
|
-const punctuationMarks = ['.', '!', '?'];
|
|
|
-
|
|
|
const {
|
|
|
randomInt,
|
|
|
capitalize,
|
|
|
getRandomArrayValue
|
|
|
} = require('./utils');
|
|
|
|
|
|
-const getRandomPunctuationMark = getRandomArrayValue.bind(null, punctuationMarks);
|
|
|
-const getRandomWord = getRandomArrayValue.bind(null, availableWords);
|
|
|
+function getRandomWord ({ availableWords}) {
|
|
|
+ return getRandomArrayValue(availableWords);
|
|
|
+}
|
|
|
|
|
|
-function createSentence ({ minWords, maxWords }) {
|
|
|
+function createSentence ({ minWords, maxWords, availableWords, punctuationMarks }) {
|
|
|
const numWords = randomInt(minWords, maxWords);
|
|
|
const sentenceWords = [];
|
|
|
|
|
|
for (let i = 0, randomWord = ''; i < numWords; i += 1) {
|
|
|
do {
|
|
|
- randomWord = getRandomWord();
|
|
|
+ randomWord = getRandomWord({ availableWords });
|
|
|
} while(sentenceWords.includes(randomWord));
|
|
|
|
|
|
// capitalize first letter when first word of sentence
|
|
@@ -40,7 +40,7 @@ function createSentence ({ minWords, maxWords }) {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- return sentenceWords.join(' ') + getRandomPunctuationMark();
|
|
|
+ return sentenceWords.join(' ') + getRandomArrayValue(punctuationMarks);
|
|
|
}
|
|
|
|
|
|
const Unit = {
|