sort: Difference between revisions
Jump to navigation
Jump to search
Killzone Kid (talk | contribs) (see also) |
Lou Montana (talk | contribs) m (Text replacement - "<sqf>([^↵][^<]*↵[^<]*)<\/sqf>" to "<sqf> $1 </sqf>") |
||
(55 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{RV|type=command | ||
| arma3 |= | |game1= arma3 | ||
|version1= 1.44 | |||
| | |gr1= Arrays | ||
|descr= Attempts to sort given array either in ascending ([[true]]) or descending ([[false]]) order. {{Feature|important|This will '''modify''' the original array!}} | |||
| | |s1= array [[sort]] order | ||
| array | |p1= array: [[Array]] - array to be sorted, can also be a nested array.<br><br> | ||
All array elements should be one of the following types: | |||
* [[String]] - Array of strings {{hl|["a","b","c"...]}} | |||
* [[Number]] - Array of numbers {{hl|[1,2,3...]}} | |||
* [[Array]] - Array of subarrays {{hl|[<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 {{hl|["a",1,[true], ...]}} are not supported and results are undefined.<br><br> | |||
| | |p2= order: [[Boolean]] - sorting order. | ||
* [[true]]: ascending | |||
* [[false]]: descending | |||
| | |r1= [[Nothing]] | ||
|x1= <sqf> | |||
_arr = [5.21725,1.30859,4,5.03028,1]; | |||
_arr sort true; | |||
|x1= < | hint str _arr; //[1,1.30859,4,5.03028,5.21725] | ||
_arr | </sqf> | ||
|x2= < | |x2= <sqf> | ||
_dev | _dev = ["ja","pa","pa","tram","tara"]; | ||
_dev sort false; | |||
hint str _dev; //["tram","tara","pa","pa","ja"] | |||
</sqf> | |||
|x3= < | |x3= <sqf> | ||
#define ASC true | |||
_scores = | #define DESC false | ||
_scores | _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]] | |||
</sqf> | |||
|x4= Sort buildings by distance and return position of the most distant building: | |||
|x4= Sort buildings by distance and return position of the most distant building:< | <sqf> | ||
{ | _buildings = player nearObjects ["Land_Cargo_Patrol_V1_F", 500]; | ||
_buildings = _buildings apply { [_x distance player, _x] }; | |||
} | _buildings sort false; | ||
_buildings | hint format [ | ||
"Most distant building is at %1, distance %2 m", | "Most distant building is at %1, distance %2 m", | ||
getPos (_buildings select 0 select 1), | |||
round (_buildings select 0 select 0) | |||
];</ | ]; | ||
</sqf> | |||
|seealso= [[lbSortBy]] [[lnbSortBy]] [[BIS_fnc_sortAlphabetically]] [[BIS_fnc_sortBy]] [[BIS_fnc_sortNum]] | |||
}} | |||
| [[ | |||
{{Note | |||
|user= Killzone_Kid | |||
|timestamp= 20150416181400 | |||
|text= The algorithm for sorting subarrays: compare 1st element, if equal compare 2nd, if equal compare 3rd...etc. | |||
}} | }} | ||
Latest revision as of 19:42, 3 September 2024
Description
- Description:
- Attempts to sort given array either in ascending (true) or descending (false) order.
- Groups:
- Arrays
Syntax
- Syntax:
- array sort order
- Parameters:
- array: Array - array to be sorted, can also be a nested array.
All array elements should be one of the following types:- String - Array of strings ["a","b","c"...]
- Number - Array of numbers [1,2,3...]
- Array - Array of subarrays [["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.
- order: Boolean - sorting order.
- Return Value:
- Nothing
Examples
- Example 1:
- Example 2:
- Example 3:
- Example 4:
- Sort buildings by distance and return position of the most distant building:
Additional Information
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 Apr 16, 2015 - 18:14 (UTC)
- The algorithm for sorting subarrays: compare 1st element, if equal compare 2nd, if equal compare 3rd...etc.