-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (72 loc) · 1.7 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
let array = require("./data/data.json");
// Creates the random number variable.
const randomNum = () => {
return Math.floor(Math.random() * array.length);
};
// Capitalizes the first letter in a string
function capitalize(str) {
const lower = str.toLowerCase()
return str.charAt(0).toUpperCase() + lower.slice(1)
}
// Get all quotes
const getAll = () => {
return array
};
// Get random quote
const getRandomQuote = () => {
let randNum = randomNum();
let grumper = array[randNum].grump;
grumper = capitalize(grumper);
return `${array[randNum].quote} -${grumper}`;
};
// get quote by grump (pass in grump name, dan, arin, etc)
const getQuotesByGrump = (grumpReq) => {
let resultsArray = [];
grumpReq = grumpReq.toLowerCase();
array.forEach(el => {
if (el.grump == grumpReq) {
resultsArray.push(el);
};
})
return resultsArray;
};
// get sfw
const getSFW = () => {
let sfwArr = []
const isSFW = array.forEach(el => {
if (el.nsfw == false) {
sfwArr.push(el);
}
})
return sfwArr
};
// get no swears
const getClean = () => {
let noSwear = []
const isSwear = array.forEach(el => {
if (el.swears == false) {
noSwear.push(el);
}
})
return noSwear
};
// get sfw and no swears
const getSFWandClean = () => {
let noNSFWorSwear = []
const isNaughty = array.forEach(el => {
if (el.swears == false && el.nsfw == false) {
noNSFWorSwear.push(el);
}
})
return noNSFWorSwear
};
// Exports
module.exports = {
getAll,
getRandomQuote,
getQuotesByGrump,
getSFW,
getClean,
getSFWandClean
};
console.log(getSFWandClean());