-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathswahili.js
More file actions
52 lines (48 loc) · 1.17 KB
/
swahili.js
File metadata and controls
52 lines (48 loc) · 1.17 KB
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
44
45
46
47
48
49
50
51
52
import list from "./words.json";
/**
* Generate an swahili of words
*
* @param Integer word_count
* @return Array|String
*/
class swahili {
/**
*
* @param {*} word_count
*/
constructor(word_count = 1) {
this.random = function () {
if (word_count == 1) {
const word = list[Math.floor(Math.random() * list.length)];
return word.sw;
} else {
const words = [];
for (let i = 1; i < word_count; i++) {
const word = list[Math.floor(Math.random() * list.length)];
words.push(word);
}
return words;
}
};
this.randomArray = function () {
const words = [];
for (let i = 1; i <= word_count; i++) {
const word = list[Math.floor(Math.random() * list.length)];
words.push(word.sw);
}
return words;
};
/**
* Generate paragraph from word_count random words
*/
this.paragraph = function () {
let words = "";
for (let i = 1; i <= word_count; i++) {
const word = list[Math.floor(Math.random() * list.length)];
words += word.sw + " ";
}
return words.trim();
};
}
}
export default swahili;