Looking for some help sorting coordinate pairs by ...
# getting-started
q
Looking for some help sorting coordinate pairs by distance from a coordinate pair.
Copy code
val origin = Source(1,1)
val source1 = Source(5,8)
val source2 = Source(3,4)
val source3 = Source(8,10)
var sources = arrayOf(source1, source2, source3)

class Source(x: Int, y: Int) {
    val x: Int = x
    val y: Int = y
}

for ( source in sources ) {
    println("${source.x}, ${source.y}")
}
Seems like I need to pass sortWith a comparator.