Skip to content

Instantly share code, notes, and snippets.

@guntaka
Created May 26, 2022 04:54
Show Gist options
  • Save guntaka/550669e3625156c17cddd8b143ad4bcb to your computer and use it in GitHub Desktop.
Save guntaka/550669e3625156c17cddd8b143ad4bcb to your computer and use it in GitHub Desktop.
Rank numbers in a list with Kotlin collection operators
val input = listOf(12000, 1000, 12000, 25000, 12000, 15000, 12000, 35000)
with(input.sorted().reversed()) {
input.map { "$it => ${indexOf(it) + 1}" }
}.forEach(::println)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment