a = [3,2,1]
arraysort(a)
a now equals
[1,2,3] a = [3,2.9,1]
arraysort(a)
a now equals
[1,2.9,3] a = ["ccc", "bbb", "aaa"]
arraysort(a)
a now equals
["aaa", "bbb", "ccc"] a = ["ccc", null, "aaa"]
arraysort(a)
a now equals
[null, "aaa", "ccc"] a = ["ccc", [7,8,9], 50]
arraysort(a)
If
func is provided, it will be called for each object in the array and expected to return the value to sort by.
function my_key(t) {
return t.name
}
a = [ { name = "c" }, { name = "a" }, { name = "b"} ]
arraysort(a, my_key)
arrayrsort(a, my_key)
Sorting arrays with different types is undefined behavior.