# sort() Function & Examples

Use the sort() matrix function in Calcul.io. Review its syntax, edit working examples, understand the result, and explore related math functions.

## sort

#### sort(x)

#### sort(x, compare)

Try it yourself:

```calculio
sort([5, 10, 1])
sort(["C", "B", "A", "D"], "natural")
sortByLength(a, b) = size(a)[1] - size(b)[1]
sort(["Langdon", "Tom", "Sara"], sortByLength)
sort(["10", "1", "2"], "natural")
```

[map](https://calcul.io/function/map/index.md)

[filter](https://calcul.io/function/filter/index.md)

---

## sort(): Ordering Collection Values

**sort()** orders values in a collection. Sorted data is useful for ranks, quantiles, binary search preparation, and readable reports.

## Ordering choices

Decide whether ascending or descending order is required and how ties should be treated. Use [compare()](https://calcul.io/function/compare/index.md) for general ordering logic and [compareText()](https://calcul.io/function/compareText/index.md) for textual values. Sorting may rearrange associated records, so preserve relationships deliberately.

Use [quantileSeq()](https://calcul.io/function/quantileSeq/index.md) for percentile analysis, [min()](https://calcul.io/function/min/index.md) and [max()](https://calcul.io/function/max/index.md) for extrema without retaining a full sorted result.

[All functions](https://calcul.io/functions/index.md)
