Skip to content

Instantly share code, notes, and snippets.

@madken
Last active March 31, 2024 07:40
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save madken/0a09b03be3af7b25c963ed585e29a7bc to your computer and use it in GitHub Desktop.
Save madken/0a09b03be3af7b25c963ed585e29a7bc to your computer and use it in GitHub Desktop.
kotlin sort a list of pairs by second and then first value
fun sortListOfPairDesc(list: List<Pair<String, Int>>): List<Pair<String, Int>> {
return list.sortedWith(compareBy({ it.second }, { it.first })).asReversed()
}
@Sarievo
Copy link

Sarievo commented May 23, 2022

also sort with first/second value then by second/first value in 2d IntArrays :>

val pro0 = fArr.sortedWith(compareBy({ it[0] }, { it[1] }))
val pro1 = fArr.sortedWith(compareBy({ it[1] }, { it[0] }))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment