Page tree
Skip to end of metadata
Go to start of metadata




Introduced in

Version:1.21

Description

Description:

Sorts an array, based on the number returned by the passed code.

The code runs on each element of the array, and the current element is passed to the code using _this. The code must return a number, and this number is used to sort the array from lowest (left) to highest (right).

The passed array is modified by reference. This function uses the Quick Sort algorithm.

To sort arrays of strings, use fn vbs sortStrings.

Syntax

Syntax:[array, code] call fn_vbs_sortArray
Parameters:
Return Value:

Array - Sorted array.

Note: The input array is also modified by reference.

Warning

When using functions in VBS versions older than 3.4, certain limitations and requirements should be kept in mind - the main ones being that capitalization of the function name is crucial, and that #include "\vbs2\headers\function_library.hpp" has to be included in every script that utilizes it. More Category VBS Scripting Functions.

Examples

Examples:
_array = [ [5], [-4], [1], [-11], [10] ];
_code = {abs (_this select 0)};

[_array, _code] call fn_vbs_sortArray;

//_array now contains: [ [1], [-4], [5], [10], [-11] ] 

Additional Information

See also: fn vbs sortStrings
Multiplayer: 
Problems: 

Notes