-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (43 loc) · 1.22 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
const bikeshare = require("./lib/bikeshare");
const get = require("./lib/utils/get");
const findBikeStationById = (stationId) => {
bikeshare
.getStationsInfo()
.then((res) => {
const station = res.stations.find(
(station) => station.station_id == stationId
);
if (station) {
console.log(station);
return station;
}
})
.catch((err) => console.error(err));
};
const findBikeStationByName = (stationName) => {
bikeshare
.getStationsInfo()
.then((res) => {
const searchRegex = new RegExp(stationName.split(" ").join(".*"), "i");
const matchingStations = res.stations.filter((station) =>
searchRegex.test(station.name)
);
if (matchingStations.length > 0) {
console.log(matchingStations);
return matchingStations;
} else {
throw new Error("No matching station found");
}
})
.catch((err) => console.error(err));
};
const getSystemInfo = bikeshare.getSystemInfo;
const getSystemPricingPlans = bikeshare.getSystemPricingPlans;
const displaySystemPricingPlans = () => {
bikeshare
.getSystemPricingPlans()
.then((res) => {
console.log(res);
})
.catch((err) => console.error(err));
};