arraySort

arraySort(array array, [function callback]) → array sortedArray
Sorts the array according to the order defined by the callback function. Elements are compared in pairs; the callback function must return a negative value, 0 or a positive value depending on whether the first value comes before, at the same level as, or after the second. If the callback function takes 2 parameters, the two values are sent; if it takes 4, the key/value pairs are sent.

Sorts the list array according to the order defined by the callback function.

The elements are compared in pairs: the callback function must return a negative value, 0 or a positive value depending on whether the first value comes before, at the same level as, or after the second value.

The default order is:

In LS1, the default order is: numbers, booleans, arrays, null elements, then strings.

Example:

var list = [4, 1, 2, 5, 3]
var result = arraySort(list, function(a, b) {
	return a - b
}) // [1, 2, 3, 4, 5]
const list = [4, 1, 2, 5, 3]
const result = [...list].sort((a, b) => a - b) // [1, 2, 3, 4, 5]
list = [4, 1, 2, 5, 3]
result = sorted(list)  # [1, 2, 3, 4, 5]
Parameters
Return
TypeScript

In JavaScript, sort() without a comparator sorts the elements as strings: [10, 9, 1] gives [1, 10, 9], not the numeric order of arraySort. Always pass a comparator for numbers: [...a].sort((x, y) => x - y), and (x, y) => y - x for descending order. sort sorts in place, hence the [...a] copy to get a new array as arraySort does; a.toSorted((x, y) => x - y) does both at once.

Python

In Python, sorted(a) returns a new sorted list, like arraySort. But there is no two-argument comparator: you sort by a key, sorted(a, key=len) or sorted(a, key=lambda e: e.life), and reverse=True reverses the order. To reuse a comparator that returns a negative, zero or positive number, wrap it: sorted(a, key=functools.cmp_to_key(comparator)). Sorting compares the elements with each other: a list mixing numbers and strings raises a TypeError.

Notes
arraySort([4, 1, 2, 5, 3], (a, b) => a - b) // [1, 2, 3, 4, 5]
[...[4, 1, 2, 5, 3]].sort((a, b) => a - b) // [1, 2, 3, 4, 5]
sorted([4, 1, 2, 5, 3])  # [1, 2, 3, 4, 5]