Brian Carbone
val Array<Coordinate>.centroid get() = fold(mutableMapOf<Double, Double>()) { acc, coord -> acc.also { it[coord.x] = coord.y } }.run { Coordinate(keys.average(), values.average()) }
Dominaezzz
val Array<Coordinate>.centroid get() = associateBy({ it.x }, { it.y }).run { Coordinate(keys.average(), values.average()) }
val Array<Coordinate>.centroid get() = Coordinate(map { it.x }.average(), map { it.y }.average())
averageBy
A modern programming language that makes developers happier.