Skip to content

Instantly share code, notes, and snippets.

@kairos34
Created October 15, 2021 08:19
Show Gist options
  • Save kairos34/0aa18862bfbc776de964c8ecb27bdbe2 to your computer and use it in GitHub Desktop.
Save kairos34/0aa18862bfbc776de964c8ecb27bdbe2 to your computer and use it in GitHub Desktop.
Write kotlin code to print the top sport by distance excluding eBikes
enum class Sport { HIKE, RUN, TOURING_BICYCLE, E_TOURING_BICYCLE }
data class Summary(val sport: Sport, val distance: Int)
fun main() {
val sportStats = listOf(Summary(Sport.HIKE, 92),
Summary(Sport.RUN, 77),
Summary(Sport.TOURING_BICYCLE, 322),
Summary(Sport.E_TOURING_BICYCLE, 656))
// Write kotlin code to print the top sport by distance excluding eBikes.
val topSport = sportStats.filterNot{ it.sport == Sport.E_TOURING_BICYCLE }.maxByOrNull{ it -> it.distance }
println(topSport?.sport)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment