API Reference › List › List.sort
method

List.sort

List.sort(s) -> void

Sorts the elements of s in ascending order in place. It is intended for slices of scalar elements (ints, entities, fixed) where < is meaningful; reference elements are ordered by identity, which is rarely useful. Small lists — the nearly-sorted, per-frame kind games usually hold — take a simple insertion sort; larger lists fall to a stable O(n log n) merge sort. Both are stable, so the result is identical either way. To sort records by a field, or in descending order, or with a custom comparator, use List.sort_by, List.sort_desc_by, or List.sort_with.

Example

program Demo {
  handler Step phase Update {
    List.sort(scores)
  }
}
← All symbols