Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify 'CBA_fnc_filter' #465

Merged
merged 1 commit into from
Aug 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;