Sort using a custom comparator: Difference between revisions

Line 2,263:
 
<lang kotlin>fun main(args: Array<String>) {
val strings = listOf("Here", "are", "some", "sample", "strings", "to", "be", "sorted")
println("Unsorted: $strings")
 
val sorted = strings.map { PairTriple (it, it.length, it.lowercase()) }.sortedWith (
kotlin.Comparator { a, b ->
compareValues(b.second, a.second).let {
if (it == 0) compareValues(a.firstthird, b.firstthird)
else it
}
}
}).map { it.first }
println("Sorted: $sorted")
}
}</lang>
 
 
{{out}}
<pre>Unsorted: [Here, are, some, sample, strings, to, be, sorted]
Sorted: [strings, sample, sorted, Here, some, are, be, to]</pre>
 
=={{header|Lua}}==
Anonymous user