ACE3/addons/common/functions/fnc_sortAlphabeticallyBy.sqf

44 lines
957 B
Plaintext
Raw Normal View History

2015-01-16 23:21:47 +00:00
/**
* fn_sortAlphabeticallyBy.sqf
* @Descr:
* @Author: Glowbal
*
* @Arguments: []
* @Return:
* @PublicAPI: true
*/
#include "script_component.hpp"
2015-05-14 18:06:06 +00:00
private ["_elements","_indexes", "_theElement", "_tmp", "_tempIndex", "_j", "_i", "_returnArray"];
PARAMS_2(_array,_elementN);
2015-01-16 23:21:47 +00:00
_indexes = [];
_elements = [];
{
2015-01-18 19:09:19 +00:00
_theElement = toArray (_x select _elementN);
_indexes pushback _foreachIndex;
_elements pushback _theElement;
2015-05-14 18:06:06 +00:00
} forEach _array;
2015-01-16 23:21:47 +00:00
for "_i" from 1 to (count _elements) - 1 do {
2015-01-18 19:09:19 +00:00
_tmp = _elements select _i;
_tempIndex = _indexes select _i;
_j = _i;
while {_j >= 1 && {_tmp < _elements select (_j - 1)}} do {
_elements set [_j, _elements select (_j - 1)];
_indexes set [_j, _indexes select (_j - 1)];
_j = _j - 1;
};
_elements set[_j, _tmp];
_indexes set [_j, _tempIndex];
2015-01-16 23:21:47 +00:00
};
_returnArray = [];
{
2015-01-18 19:09:19 +00:00
_returnArray pushback (_array select _x);
2015-05-14 18:06:06 +00:00
} forEach _indexes;
2015-01-16 23:21:47 +00:00
_returnArray;