Arma 3 Scripting

sort

  • Arma 3 v1.44

Command · Markdown · JSON · original wiki page

Description

Attempts to sort given array either in ascending (true) or descending (false) order.

Important

This will modify the original array!

Syntax

array sort order

Parameters:

Returns: 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)
];

See also

lbSortBy · lnbSortBy · BIS_fnc_sortAlphabetically · BIS_fnc_sortBy · BIS_fnc_sortNum

Community notes

Killzone_Kid

The algorithm for sorting subarrays: compare 1st element, if equal compare 2nd, if equal compare 3rd...etc.