Skip to content

Commit

Permalink
Fix averages with 0s (#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
devinmatte authored Jul 7, 2023
1 parent c604513 commit 242c575
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions common/utils/traveltimes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import type { AggregateDataPoint, SingleDayDataPoint } from '../types/charts';
const averageTravelTime = (traveltimes: (number | undefined)[]) => {
if (traveltimes && traveltimes.length >= 1) {
const totalSum = traveltimes.reduce((a, b) => {
if (a && b) {
if (a !== undefined && b !== undefined) {
return a + b;
} else {
return 0;
}
});
}, 0);
return (totalSum || 0) / traveltimes.length;
} else {
return 0;
Expand Down

0 comments on commit 242c575

Please sign in to comment.