如何按距离打印顶级运动,不包括 kotlin 中的电动自行车?

how print the top sport by distance excluding eBikes in kotlin?

我想在 kotlin 中按距离打印顶级运动,不包括 eBikes 我该如何实现

低于我的 Kotlin 类

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))
    
   
}

给你:

sportStats
    .filterNot { it.sport == Sport.E_TOURING_BICYCLE }
    .maxBy { it.distance }
    ?.let { (sport, distance) -> 
        println("$sport is the top with distance $distance") 
    }

结果:

TOURING_BICYCLE is the top with distance 322