Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions examples/05_Collections/14_sorted.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@
`sortedBy` sorts elements according to natural sort order of the values returned by specified selector function.

```run-kotlin
//sampleStart
import kotlin.math.abs

fun main() {

//sampleStart
val shuffled = listOf(5, 4, 2, 1, 3, -10) // 1
val natural = shuffled.sorted() // 2
val inverted = shuffled.sortedBy { -it } // 3
val descending = shuffled.sortedDescending() // 4
val descendingBy = shuffled.sortedByDescending { abs(it) } // 5
//sampleEnd

println("Shuffled: $shuffled")
println("Natural order: $natural")
println("Inverted natural order: $inverted")
println("Inverted natural order value: $descending")
println("Inverted natural order of absolute values: $descendingBy")
}
//sampleEnd
```

1. Defines a collection of shuffled numbers.
Expand Down