Skip to content

Commit

Permalink
Merge pull request #465 from CBATeam/simplify-filter
Browse files Browse the repository at this point in the history
simplify 'CBA_fnc_filter'
  • Loading branch information
Killswitch00 committed Aug 15, 2016
2 parents 219d289 + a082a4c commit 1f22d8f
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions addons/arrays/fnc_filter.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ARRAY>
_filter - Function to filter each element <CODE>
_inPlace - true: alter array, false: copy array (optional, default: false) <BOOLEAN>
Returns:
Filtered array [Array]
Filtered array <ARRAY>
Examples:
(begin example)
Expand All @@ -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;

0 comments on commit 1f22d8f

Please sign in to comment.