Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chunlaw committed Aug 14, 2024
2 parents 3adccf4 + 65c2b8b commit 1369aa8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ctb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function fetchEtas({
.then((response) => response.json())
.then(({ data }) =>
data
.filter((eta: any) => eta.eta && bound.includes(eta.dir))
.filter((eta: any) => bound.includes(eta.dir))
// filter the eta by the stop sequence information
// as the route data may not 100% match
// use the nearest seq
Expand Down
14 changes: 9 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,15 @@ export async function fetchEtas({
}
}

return _etas.sort((a, b) => {
if (a.eta === "") return 1;
else if (b.eta === "") return -1;
return a.eta < b.eta ? -1 : 1;
});
if (_etas.some((e) => e.eta)) {
_etas = _etas.filter((e) => e.eta);
}
return _etas
.sort((a, b) => {
if (!a.eta || a.eta === "") return 1;
else if (!b.eta || b.eta === "") return -1;
return a.eta < b.eta ? -1 : 1;
});
} catch (err) {
console.error(err);
return [];
Expand Down
2 changes: 1 addition & 1 deletion src/kmb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function fetchEtas({
.then((response) => response.json())
.then(({ data }) =>
data
.filter((e: any) => e.eta !== null && e.dir === bound)
.filter((e: any) => e.dir === bound)
.sort((a: any, b: any) =>
Math.abs(a.seq - seq) < Math.abs(b.seq - seq) ? -1 : 1,
)
Expand Down

0 comments on commit 1369aa8

Please sign in to comment.