Created
October 15, 2021 08:19
-
-
Save kairos34/0aa18862bfbc776de964c8ecb27bdbe2 to your computer and use it in GitHub Desktop.
Write kotlin code to print the top sport by distance excluding eBikes
This file contains hidden or 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
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