-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathfunctions.js
33 lines (29 loc) · 911 Bytes
/
functions.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
const webSeries = require("./web-series/index.json");
function randomSeries() {
let random = Math.floor(Math.random() * webSeries.length);
return webSeries[random];
}
function ratingSeries(r) {
let random = Math.floor(Math.random() * webSeries.length);
while (true) {
if (webSeries[random].rating >= r) {
return webSeries[random];
} else {
random = (random + 1) % webSeries.length;
}
}
}
function genreSeries(genre) {
let requiredSeries = [];
for (let i = 0; i < webSeries.length; i++) {
let thatSeries = webSeries[i];
for (let j = 0; j < thatSeries.category.length; j++) {
if (webSeries[i].category[j].localeCompare(genre) === 0) {
requiredSeries.push(thatSeries);
}
}
}
let random = Math.floor(Math.random() * requiredSeries.length);
return requiredSeries[random];
}
module.exports = { randomSeries, ratingSeries, genreSeries };