-
Notifications
You must be signed in to change notification settings - Fork 8
sortArray
MicroBlaster edited this page Oct 13, 2019
·
7 revisions
Purpose: Sorts a two dimensional array by selected column.
Syntax: sortArray [$array] [$column] [$order] {$filename}
$array: The array to be sorted.
$column: Column to sort the array.
$order: Sort direction - A for Ascending or D for Descending.
$filename: Optional filename to load the array from.
Notes: This command can be used to sort an array in memory, or it can load an array from a file like readToArray.
The array will be created, sorted and populated in one step. Any existing array with the same name will first be overwritten. Also, a variable with the same name as the array will be created, and its integer value will be the the element count of the array.
Example:
#Sort an array in memory
sortArray $Ships 2 A
# Read a text file into a sorted array
sortArray $Ships 2 A ships.txt
echo "*Ships read:" $ShipArray
setVar $i 1
while ($i <= $ShipArray)
echo "*" $ShipArray[$i]
add $i 1
end
.