From a082a4c5503f3f09f697cc50f8c1c07e0ce7f5a4 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 14 Aug 2016 23:15:58 +0200 Subject: [PATCH] simplify 'CBA_fnc_filter' --- addons/arrays/fnc_filter.sqf | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/addons/arrays/fnc_filter.sqf b/addons/arrays/fnc_filter.sqf index 1f09108bd..7e53fbadd 100644 --- a/addons/arrays/fnc_filter.sqf +++ b/addons/arrays/fnc_filter.sqf @@ -8,12 +8,12 @@ Description: * _x - Element of _array. Parameters: - _array - Array of key-value pairs to create Hash from [Array, defaults to []] - _filter - Function to filter each element [Function] - _inPlace - True to alter the array itself, rather than create a new one [Boolean, defaults to false] + _array - Array + _filter - Function to filter each element + _inPlace - true: alter array, false: copy array (optional, default: false) Returns: - Filtered array [Array] + Filtered array Examples: (begin example) @@ -30,29 +30,19 @@ Examples: (end) Author: - Spooner + Spooner, commy2 ---------------------------------------------------------------------------- */ - #include "script_component.hpp" - SCRIPT(filter); -// ----------------------------------------------------------------------------- - -params ["_array","_filter", ["_inPlace",false]]; - -private ["_arrayOut", "_x"]; +params [["_array", [], [[]]], ["_filter", {_x}, [{}]], ["_inPlace", false, [false]]]; if (_inPlace) then { - _arrayOut = _array; -} else { - _arrayOut = []; - _arrayOut resize (count _array); -}; + { + _array set [_forEachIndex, call _filter]; + } forEach _array; -for "_i" from 0 to ((count _array) - 1) do { - _x = _array select _i; - _arrayOut set [_i, call _filter]; + _array // return +} else { + _array apply _filter // return }; - -_arrayOut;