Name
Sort -- sort an array
Synopsis
Sort(array[, sortfunc])
Function
This function sorts the array specified by array. It supports arrays of type number, type string or an arbitrary data type via a custom callback. This function stops sorting if it finds a Nil element or an empty string ("") in string arrays. String arrays are sorted alphabetically, number arrays are sorted in ascending order.

Starting with Hollywood 4.5, you can customize the sorting operation by using a custom sort callback. This function has to accept two parameters and it has to return if the first parameter should be inserted before the second one or not. This gives you great flexibility in setting up custom sort operations because you can compare arbitrary values and you can also customize the sorting order.

Inputs
array
array to sort
sortfunc
optional: custom function telling Hollywood how to sort (V4.5)
Example
names = {"Joey", "Dave", "Mark", "Stephen", "Al", "Jefferson"}
Sort(names)
For k = 0 To 5
   NPrint(names[k])
Next
The above code defines an array, adds some names to it and then sorts it. The output is "Al, Dave, Jefferson, Joey, Mark, Stephen".


nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Sort(nums, Function(a, b) Return(a > b) EndFunction)
For k = 0 To 9
   NPrint(nums[k])
Next
The code above uses a custom sorting function to sort table "nums" in descending order. The result will be: 10, 9, 8, 7, 6, 5, 4, 3, 2, 1.

Show TOC