{"name":"BIS_fnc_sortBy","operator":null,"title":"BIS fnc sortBy","type":"function","url":"https://community.bistudio.com/wiki/BIS_fnc_sortBy","revid":327964,"updated":"2022-07-13T13:57:43Z","groups":["Arrays"],"status":"ok","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"0.58"}],"since":{"game":"arma3","name":"Arma 3","version":"0.58"},"arma3_since":"0.58","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Sorts an array according to given algorithm. See sort for simple sorts.","syntaxes":[{"syntax":"[array, parameters, algorithm, direction, filter] call BIS_fnc_sortBy","since":null,"effect":null,"exec":null,"params":[{"name":"array","type":"Array","optional":false,"default":null,"description":"any unsorted array. Can contain any types","types":["Array"],"since":null,"text":"array: Array - any unsorted array. Can contain any types"},{"name":"parameters","type":"Array","optional":false,"default":null,"description":"Array\n- used in the eval algorithm\n- input params are referenced in the sorting algorithm by _input0..9\n- a maximum of 10 input params is supported (0-9)","types":["Array"],"since":null,"text":"parameters: Array\n- used in the eval algorithm\n- input params are referenced in the sorting algorithm by _input0..9\n- a maximum of 10 input params is supported (0-9)"},{"name":"algorithm","type":"Code","optional":true,"default":"`{ _x }`","description":"needs to return String, Number or Array - see sort\n- _x refers to array item","types":["Code"],"since":null,"text":"algorithm: Code - (Optional, default `{ _x }`)\n- needs to return String, Number or Array - see sort\n- _x refers to array item"},{"name":"direction","type":"String","optional":true,"default":"\"ASCEND\"","description":"case-insensitive\n- \"ASCEND\" for ascending sorting\n- \"DESCEND\" (or anything else) for descending sorting","types":["String"],"since":null,"text":"direction: String - (Optional, default \"ASCEND\") case-insensitive\n- \"ASCEND\" for ascending sorting\n- \"DESCEND\" (or anything else) for descending sorting"},{"name":"filter","type":"Code","optional":true,"default":"`{ true }`","description":"code that needs to evaluate true for the array item to be sorted, otherwise item is removed","types":["Code"],"since":null,"text":"filter: Code - (Optional, default `{ true }`) code that needs to evaluate true for the array item to be sorted, otherwise item is removed"}],"returns":{"type":"Array","types":["Array"],"description":"sorted array","text":"Array - sorted array"}}],"examples":[{"text":"```sqf\n// sort numbers from lowest to highest\n_sortedNumbers = [[1,-80,0,480,15,-40], [], {_x}, \"ASCEND\"] call BIS_fnc_sortBy;\n```","code":["// sort numbers from lowest to highest\n_sortedNumbers = [[1,-80,0,480,15,-40], [], {_x}, \"ASCEND\"] call BIS_fnc_sortBy;"]},{"text":"```sqf\n// sort helicopters by distance from player\n_closestHelicopters = [[_heli1,_heli2,_heli3], [], { player distance _x }, \"ASCEND\"] call BIS_fnc_sortBy;\n```","code":["// sort helicopters by distance from player\n_closestHelicopters = [[_heli1,_heli2,_heli3], [], { player distance _x }, \"ASCEND\"] call BIS_fnc_sortBy;"]},{"text":"```sqf\n// sort enemy by distance from friendly unit (referenced by local variable), the furthest first\n_furtherstEnemy = [[_enemy1,_enemy2,_enemy3], [_friendly], { _input0 distance _x }, \"DESCEND\", { canMove _x }] call BIS_fnc_sortBy;\n```","code":["// sort enemy by distance from friendly unit (referenced by local variable), the furthest first\n_furtherstEnemy = [[_enemy1,_enemy2,_enemy3], [_friendly], { _input0 distance _x }, \"DESCEND\", { canMove _x }] call BIS_fnc_sortBy;"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["BIS_fnc_sortAlphabetically","BIS_fnc_sortNum","sort"],"notes":[],"categories":["Arma 3: Functions","Arma 3: New Functions","Function Group: Arrays","Functions","Introduced with Arma 3 version 0.58"],"docblock":null,"filled_from_docblock":[]}