Sort(array[, sortfunc])
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.
names = {"Joey", "Dave", "Mark", "Stephen", "Al", "Jefferson"} Sort(names) For k = 0 To 5 NPrint(names[k]) NextThe 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]) NextThe 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.