Skip to content

Commit b712c25

Browse files
committed
fix: make sure startDate is actually the first date
1 parent c035213 commit b712c25

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

TypeScript/TollCalculator.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ class TollCalculator {
1414
}
1515

1616
getTotalTollFee(vehicle: Vehicle, dates: Date[]) {
17-
const startDate = dates[0];
17+
const sortedDates = [...dates].sort();
18+
const startDate = sortedDates[0];
1819
let lastBillingDate = null;
1920
let tempFee = null;
2021
let totalFee = 0;
2122

22-
dates.sort().forEach((date: Date) => {
23+
sortedDates.sort().forEach((date: Date) => {
2324
if (!this.isSameDay(date, startDate)) {
2425
throw "Billings must be in the same day.";
2526
}

0 commit comments

Comments
 (0)