sort: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - "_{10,} " to "") |
Lou Montana (talk | contribs) m (Text replacement - " *\| *([Cc]omments|COMMENTS|Game|[Gg]ame [Nn]ame( +[0-9])?|Game [Vv]ersion( +[0-9])?|Game Version \(number surrounded by NO SPACES\)|Arguments in MP|MP[Aa]rg|Multiplayer Arguments( \("local" or "global"\))?|Effects|Execution|Effects...) |
||
Line 1: | Line 1: | ||
{{Command | {{Command | ||
| arma3 | | arma3 | ||
|1.44 | |1.44 | ||
|gr1= Arrays | |gr1= Arrays | ||
| Attempts to sort given array either in ascending ([[true]]) or descending ([[false]]) order. All array elements should be one of the following types: | | Attempts to sort given array either in ascending ([[true]]) or descending ([[false]]) order. All array elements should be one of the following types: | ||
Line 11: | Line 11: | ||
* [[Number]] - array of numbers ([1,2,3...]) | * [[Number]] - array of numbers ([1,2,3...]) | ||
* [[Array]] - array of subarrays (<nowiki>[</nowiki>["a",1,2],["b",3,4],["c",5,6]...]). Subarrays should be of the same structure. Subarray elements other than [[String]] or [[Number]] will be ignored during sorting. | * [[Array]] - array of subarrays (<nowiki>[</nowiki>["a",1,2],["b",3,4],["c",5,6]...]). Subarrays should be of the same structure. Subarray elements other than [[String]] or [[Number]] will be ignored during sorting. | ||
Mixed arrays (["a",1,[true]...]) are not supported and results are undefined. | Mixed arrays (["a",1,[true]...]) are not supported and results are undefined. | ||
| array '''sort''' order | | array '''sort''' order | ||
|p1= array: [[Array]] | |p1= array: [[Array]] | ||
|p2= order: [[Boolean]] - [[true]]: ascending, [[false]]: descending | |p2= order: [[Boolean]] - [[true]]: ascending, [[false]]: descending | ||
| [[Nothing]] | | [[Nothing]] | ||
|x1= <code>_arr = [5.21725,1.30859,4,5.03028,1]; | |x1= <code>_arr = [5.21725,1.30859,4,5.03028,1]; | ||
_arr [[sort]] [[true]]; | _arr [[sort]] [[true]]; | ||
[[hint]] [[str]] _arr; //[1,1.30859,4,5.03028,5.21725]</code> | [[hint]] [[str]] _arr; //[1,1.30859,4,5.03028,5.21725]</code> | ||
|x2= <code>_dev = ["ja","pa","pa","tram","tara"]; | |x2= <code>_dev = ["ja","pa","pa","tram","tara"]; | ||
_dev [[sort]] [[false]]; | _dev [[sort]] [[false]]; | ||
[[hint]] [[str]] _dev; //["tram","tara","pa","pa","ja"]</code> | [[hint]] [[str]] _dev; //["tram","tara","pa","pa","ja"]</code> | ||
|x3= <code><nowiki>#</nowiki>define ASC true | |x3= <code><nowiki>#</nowiki>define ASC true | ||
Line 33: | Line 33: | ||
_scores = [<nowiki/>[123,"bob",15],[123,"bill",20],[200,"dave",21],[200,"steve",11]]; | _scores = [<nowiki/>[123,"bob",15],[123,"bill",20],[200,"dave",21],[200,"steve",11]]; | ||
_scores [[sort]] DESC; | _scores [[sort]] DESC; | ||
[[hint]] [[str]] _scores; //<nowiki>[</nowiki>[200,"steve",11],[200,"dave",21],[123,"bob",15],[123,"bill",20]]</code> | [[hint]] [[str]] _scores; //<nowiki>[</nowiki>[200,"steve",11],[200,"dave",21],[123,"bob",15],[123,"bill",20]]</code> | ||
Line 43: | Line 43: | ||
[[getPos]] (_buildings [[select]] 0 [[select]] 1), | [[getPos]] (_buildings [[select]] 0 [[select]] 1), | ||
[[round]] (_buildings [[select]] 0 [[select]] 0) | [[round]] (_buildings [[select]] 0 [[select]] 0) | ||
];</code> | ];</code> | ||
| [[set]], [[pushBack]], [[pushBackUnique]], [[apply]], [[select]], [[resize]], [[reverse]], [[count]], [[find]], [[in]], [[forEach]], [[deleteAt]], [[deleteRange]], [[append]], [[toArray]], [[toString]], [[param]], [[params]], [[arrayIntersect]], [[splitString]], [[joinString]], [[BIS_fnc_sortAlphabetically]], [[BIS_fnc_sortBy]], [[BIS_fnc_sortNum]] | | [[set]], [[pushBack]], [[pushBackUnique]], [[apply]], [[select]], [[resize]], [[reverse]], [[count]], [[find]], [[in]], [[forEach]], [[deleteAt]], [[deleteRange]], [[append]], [[toArray]], [[toString]], [[param]], [[params]], [[arrayIntersect]], [[splitString]], [[joinString]], [[BIS_fnc_sortAlphabetically]], [[BIS_fnc_sortBy]], [[BIS_fnc_sortNum]] | ||
}} | }} |
Revision as of 11:24, 18 January 2021
Description
- Description:
- Attempts to sort given array either in ascending (true) or descending (false) order. All array elements should be one of the following types: Mixed arrays (["a",1,[true]...]) are not supported and results are undefined.
- Groups:
- Arrays
Syntax
- Syntax:
- array sort order
- Parameters:
- array: Array
- order: Boolean - true: ascending, false: descending
- Return Value:
- Nothing
Examples
- Example 1:
_arr = [5.21725,1.30859,4,5.03028,1]; _arr sort true; hint str _arr; //[1,1.30859,4,5.03028,5.21725]
- Example 2:
_dev = ["ja","pa","pa","tram","tara"]; _dev sort false; hint str _dev; //["tram","tara","pa","pa","ja"]
- Example 3:
#define ASC true #define DESC false _scores = [[123,"bob",15],[123,"bill",20],[200,"dave",21],[200,"steve",11]]; _scores sort DESC; hint str _scores; //[[200,"steve",11],[200,"dave",21],[123,"bob",15],[123,"bill",20]]
- Example 4:
- Sort buildings by distance and return position of the most distant building:
_buildings = player nearObjects ["Land_Cargo_Patrol_V1_F", 500]; _buildings = _buildings apply { [_x distance player, _x] }; _buildings sort false; hint format [ "Most distant building is at %1, distance %2 m", getPos (_buildings select 0 select 1), round (_buildings select 0 select 0) ];
Additional Information
- See also:
- setpushBackpushBackUniqueapplyselectresizereversecountfindinforEachdeleteAtdeleteRangeappendtoArraytoStringparamparamsarrayIntersectsplitStringjoinStringBIS_fnc_sortAlphabeticallyBIS_fnc_sortByBIS_fnc_sortNum
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
- Posted on April 16, 2015 - 18:14 (UTC)
- Killzone Kid
- The algorithm for sorting subarrays: compare 1st element, if equal compare 2nd, if equal compare 3rd...etc.