BIS fnc sortBy: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(see also)
No edit summary
Line 3: Line 3:
____________________________________________________________________________________________
____________________________________________________________________________________________


| arma3 |= Game name
|arma3 |= Game name


|0.58|= Game version
|0.58|= Game version
____________________________________________________________________________________________
____________________________________________________________________________________________


| <pre>/*
|Sorts an array according to given algorithm.|= Description
 
____________________________________________________________________________________________
Description:
|[] call [[BIS_fnc_sortBy]]; |= Syntax
Sorts an array according to given algorithm.
____________________________________________________________________________________________
 
|p1= [[Array]] - Unsorted array which can contain any types ([[object]]/[[numbers]]/[[strings]] ..) |= Parameter 1
Parameter(s):
|p2= [[Array]] - - used in the eval algorithm (object/numbers/strings ..)
_this select 0: any unsorted array (Array)
                - input params are referenced in the sorting algorithm by _input0, _input1 .. _input9
- array can contain any types (object/numbers/strings ..)
                - max. number of 10 input params is supported (0-9)|= Parameter 2


_this select 1: input parameters (Array)
|p3= [[Code]] - sorted algorithm [optional: default {_x}] |= Parameter 3
- used in the eval algorithm (object/numbers/strings ..)
- input params are referenced in the sorting algorithm by _input0, _input1 .. _input9
- max. number of 10 input params is supported (0-9)


_this select 2: sorted algorithm (Code) [optional: default {_x}]
|p4= [[String]] -sort direction [optional: default "ASCEND"]
- code needs to return a scalar
- variable _x refers to array item
 
_this select 3: sort direction (String) [optional: default "ASCEND"]
"ASCEND": sorts array in ascending direction (from lowest value to highest)
"ASCEND": sorts array in ascending direction (from lowest value to highest)
"DESCEND": sorts array in descending direction
"DESCEND": sorts array in descending direction |= Parameter 4


_this select 4: filter (Code) [optional: default {true}]
- code that needs to evaluate true for the array item to be sorted, otherwise item is removed


Returns:
|p5= [[Code]] -  filter default {true}] - code that needs to evaluate true for the array item to be sorted, otherwise item is removed |= Parameter 5
Array


Examples:
____________________________________________________________________________________________
 
|[[Array]]|= Return value
//sort numbers from lowest to highest
_sortedNumbers = [[1,-80,0,480,15,-40],[],{_x},"ASCEND"] call BIS_fnc_sortBy;
 
//sort helicopters by distance from player
_closestHelicopters = [[_heli1,_heli2,_heli3],[],{player distance _x},"ASCEND"] call BIS_fnc_sortBy;
 
//sort enemy by distance from friendly unit (referenced by local variable), the furtherest first
_furtherstEnemy = [[_enemy1,_enemy2,_enemy3],[_friendly],{_input0 distance _x},"DESCEND",{canMove _x}] call BIS_fnc_sortBy;
*/
 
</pre><small>''(Placeholder description extracted from the function header by [[BIS_fnc_exportFunctionsToWiki]])''</small> |= Description
____________________________________________________________________________________________
____________________________________________________________________________________________


| <!-- [] call [[BIS_fnc_sortBy]]; --> |= Syntax


|p1= |= Parameter 1
| |= Return value
____________________________________________________________________________________________
____________________________________________________________________________________________


|x1= <code></code> |=
____________________________________________________________________________________________


| [[BIS_fnc_sortAlphabetically]], [[BIS_fnc_sortNum]], [[sort]] |= See also
| [[BIS_fnc_sortAlphabetically]], [[BIS_fnc_sortNum]], [[sort]] |= See also

Revision as of 15:00, 2 April 2016


Hover & click on the images for description

Description

Description:
Sorts an array according to given algorithm.
Execution:
call
Groups:
Uncategorised

Syntax

Syntax:
[] call BIS_fnc_sortBy;
Parameters:
Array - Unsorted array which can contain any types (object/numbers/strings ..)
Array - - used in the eval algorithm (object/numbers/strings ..) - input params are referenced in the sorting algorithm by _input0, _input1 .. _input9 - max. number of 10 input params is supported (0-9)
Code - sorted algorithm [optional: default {_x}]
String -sort direction [optional: default "ASCEND"] "ASCEND": sorts array in ascending direction (from lowest value to highest) "DESCEND": sorts array in descending direction
Code - filter default {true}] - code that needs to evaluate true for the array item to be sorted, otherwise item is removed
Return Value:
Array

Examples

Examples:
Example needed

Additional Information

See also:
BIS_fnc_sortAlphabeticallyBIS_fnc_sortNumsort

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note

Notes

Bottom Section