-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (40 loc) · 956 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
const data = require("./quotes.json");
const getAllQuotes = () => {
return data;
};
const getQuotesByCategory = (category) => {
const categorizedQuotes = data.filter((quote) => {
return quote.category === category;
});
return categorizedQuotes;
};
const getQuotesByAuthor = (author) => {
const filterByAuthor = data.filter((quote) => {
return quote.by === author;
});
return filterByAuthor;
};
const getTodaysQuote = () => {
const length = data.length;
const number = Math.floor(Math.random() * length);
const todaysQuote = data[number];
return todaysQuote;
};
const getQuoteById = (quoteId) => {
return data[quoteId];
};
const getAllCategories = () => {
const arr = data.map((quote) => {
return quote.category;
});
const categories = [...new Set(arr)];
return categories;
};
module.exports = {
getQuoteById,
getAllQuotes,
getQuotesByAuthor,
getQuotesByCategory,
getTodaysQuote,
getAllCategories,
};