The SortArray method sorts an array in either ascending or descending order. It can handle arrays of numbers, strings, and two-dimensional arrays (sorting by the first element of each sub-array).
SortArray
public SortArray<T>( array: T[], count: number = APIConstants.ARRAY_ENTIRE, start = 0, direction = APIConstants.SORT_ASCENDING ): boolean
array: The array to be sorted
array
count: Optional. The number of elements to sort. Default is ARRAY_ENTIRE
count
start: Optional. The starting index for sorting. Default is 0
start
direction: Optional. The sort direction (SORT_ASCENDING or SORT_DESCENDING). Default is SORT_ASCENDING
direction
Returns a boolean indicating whether the sorting operation was successful. Returns false if the range is invalid.
boolean
Last updated 9 months ago
// Sorting numbers const prices = [10.5, 11.2, 10.8, 11.5, 10.9]; this.api.SortArray(prices); console.log("Sorted prices:", prices); // Sorting strings const symbols = ["EURUSD", "GBPUSD", "AUDUSD", "USDJPY"]; this.api.SortArray(symbols); console.log("Sorted symbols:", symbols); // Sorting in descending order const volumes = [0.1, 0.5, 0.3, 0.2, 0.4]; this.api.SortArray( volumes, this.api.APIConstants.ARRAY_ENTIRE, 0, this.api.APIConstants.SORT_DESCENDING ); console.log("Sorted volumes (descending):", volumes); // Sorting a portion of the array const rates = [1.1234, 1.1567, 1.1345, 1.1789, 1.1456]; this.api.SortArray(rates, 3, 1); // Sort 3 elements starting from index 1 console.log("Partially sorted rates:", rates);