Clib.qsort()
syntax: |
Clib.qsort(array[, elementCount], compareFunction) |
where: |
array - array to sort.
elementCount - number of elements to sort. Default is the entire array.
compareFunction - function used to compare key with each element searched in the array.
|
return: |
void.
|
description: |
This method sorts elements in an array, starting from index 0 to elementCount1. If elementCount is not supplied, then it will sort the entire array. This method differs from the Array sort() method in that it can sort automatically created arrays, whereas Array sort() only works with arrays explicitly created with a new Array() statement.
The value of elementCount is limited to 64K
|
see: |
|
example: |
// Create a list of color names, // sort the list in reverse alphabetical order, // case insensitive, and display the list.
// initialize an array of colors var colors = {"yellow", "Blue", "GREEN", "purple", "RED", "BLACK", "white", "orange"};
// sort the list ReverseColorSorter function Clib.qsort(colors, ReverseColorSorter);
// display the sorted colors for (var i = 0; i < getArrayLength(colors); i++) Clib.puts(colors[i]);
function ReverseColorSorter(color1,color2) // do a simple case insensitive string // comparison, and reverse the results too { var CompareResult = Clib.stricmp(color1,color2) return -CompareResult; }
// The output is: // yellow // white // RED // purple // orange // GREEN // Blue // BLACK |