-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// metro-now | ||
// https://github.com/krystxf/metro-now | ||
|
||
func uniqueBy<T, E: Hashable>(array: [T], by keySelector: (T) -> E) -> [T] { | ||
var seen = Set<E>() | ||
return array.filter { element in | ||
let key = keySelector(element) | ||
return seen.insert(key).inserted | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
apps/mobile/metro-now/metro-now/utils/find-closest-stop.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// metro-now | ||
// https://github.com/krystxf/metro-now | ||
|
||
import CoreLocation | ||
import SwiftUI | ||
|
||
func findClosestStop(to location: CLLocation, stops: [ApiStop]) -> ApiStop? { | ||
var closestStop: ApiStop? | ||
var closestDistance: CLLocationDistance? | ||
|
||
for stop in stops { | ||
let stopLocation = CLLocation(latitude: stop.avgLatitude, longitude: stop.avgLongitude) | ||
|
||
let distance = location.distance(from: stopLocation) | ||
|
||
guard closestDistance != nil else { | ||
closestStop = stop | ||
closestDistance = distance | ||
continue | ||
} | ||
|
||
if distance < closestDistance! { | ||
closestStop = stop | ||
closestDistance = distance | ||
} | ||
} | ||
|
||
return closestStop | ||
} |
10 changes: 10 additions & 0 deletions
10
apps/mobile/metro-now/metro-now/utils/get-platform-label.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// metro-now | ||
// https://github.com/krystxf/metro-now | ||
|
||
func getPlatformLabel(_ platform: ApiPlatform) -> String { | ||
if let code = platform.code { | ||
return "\(platform.name) \(code)" | ||
} | ||
|
||
return platform.name | ||
} |