sort: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 44: Line 44:
[[Category:Scripting_Commands_Arma_3]]
[[Category:Scripting_Commands_Arma_3]]
[[Category:Command_Group:_Variables|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_Variables|{{uc:{{PAGENAME}}}}]]
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on April 16, 2015 - 18:14 (UTC)</dd>
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
<dd class="note">
The algorithm for sorting subbarrays: compare 1st element, if equal compare 2nd, if equal compare 3rd...etc.
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Revision as of 20:14, 16 April 2015

-wrong parameter ("arma3dev") defined!-[[:Category:Introduced with arma3dev version 1.43|1.43]]
Hover & click on the images for description

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:
  • 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.
Mixed arrays (["a",1,[true]...]) are not supported and results are undefined.
Groups:
Uncategorised

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:
_scores = [[123,"bob",15],[123,"bill",20],[200,"dave",21],[200,"steve",11]]; _scores sort false; hint str _scores; //[[200,"steve",11],[200,"dave",21],[123,"bob",15],[123,"bill",20]]

Additional Information

See also:
setpushBackresizereversecountfindinforEachdeleteAtdeleteRangeappendtoArraytoString

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

[[Category:Introduced with arma3dev version 1.43]][[ Category: arma3dev: New Scripting Commands | SORT]][[ Category: arma3dev: Scripting Commands | SORT]]

Posted on April 16, 2015 - 18:14 (UTC)
Killzone Kid
The algorithm for sorting subbarrays: compare 1st element, if equal compare 2nd, if equal compare 3rd...etc.