Avoid duplicate Best Value rank crashes

This commit is contained in:
FuelBoard Contributor
2026-10-13 12:15:00 +01:00
parent 9aa8a2ede1
commit 8436e87398
2 changed files with 27 additions and 5 deletions
+6 -5
View File
@@ -499,11 +499,12 @@ enum FuelSavingsEstimator {
pricePencePerLitre: station.prices[fuel] ?? .infinity
)
}
let order = Dictionary(
uniqueKeysWithValues: FuelSavingsCalculator.sortedForWorthTheDrive(ranked)
.enumerated()
.map { ($0.element.stationID, $0.offset) }
)
var order: [String: Int] = [:]
for (offset, rankedStation) in FuelSavingsCalculator.sortedForWorthTheDrive(ranked).enumerated() {
if order[rankedStation.stationID] == nil {
order[rankedStation.stationID] = offset
}
}
return stations.sorted { lhs, rhs in
let left = order[lhs.id] ?? Int.max
let right = order[rhs.id] ?? Int.max