Ad space (banner)
๐ŸŸฃJulia Lessons
Lesson 11 / 68

Sorting an array

This lesson covers sorting an array with Julia's sort, with the aim of understanding an operation used constantly in practice.

sort() reorders an array. Rather than changing the original in place, it returns a new sorted array — a functional touch characteristic of Julia.

The sample code assigns a new, ascending-order array to sorted_nums with sort(nums). Note that the default order is ascending.

A common early stumble is the difference between sort() and sort!(). The exclamation-marked sort!() rewrites the original array in place — by Julia convention, a name ending in "!" changes its argument.

In professional work, sorting is an everyday operation — ranking displays, ordering search results.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Julia directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)