-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
35 lines (29 loc) · 934 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
34
35
const routeData = require("./Nairobi-route-data.json");
// console.log(routeData.routes);
const filterByStopName = (stopName) => {
stopName = stopName.toLowerCase();
return routeData.routes.filter((route) => {
let stops = route.stops.map((stop) => stop.toLowerCase());
return stops.includes(stopName);
});
};
isStopFound = (stopName) => {
return filterByStopName(stopName).length > 0;
};
const getBusPickupPoints = async (stopName) => {
return filterByStopName(stopName).length > 1
? // the values adding or in between the values
filterByStopName(stopName)
.map((route) => route.pickup_point)
.reduce((a, b) => a.concat(b))
: filterByStopName(stopName).map((route) => route.pickup_point);
};
const getRouteNumbers = async (stopName) => {
return filterByStopName(stopName).map((route) => route.number);
};
module.exports = {
// filterByStopName,
isStopFound,
getBusPickupPoints,
getRouteNumbers,
};