CBA_fnc_inject

Description

Accumulates a value by passing elements of an array “through” a function.

Data passed to the function on each iteration,

  • _accumulator - Value passed from last iteration, set to _initial for the first iteration.
  • _x - Element of _array.

Parameters

_arrayArray of key-value pairs to create Hash from [Array]
_initialInitial value to pass into the function as _accumulator [Any]
_functionCode to pass values to [Function]

Returns

Accumlated value [Any]

Examples

_result = [[1, 2, 3], "", { _accumulator + (str _x) }] call CBA_fnc_inject;
// _result ==> "123"

_result = [[1, 2, 3], " frogs", { (str _x) + _accumulator }] call CBA_fnc_inject;
// _result ==> "321 frogs"

_result = [[1, 2, 3], 0, { _accumulator + _x }] call CBA_fnc_inject;
// _result ==> 6

Author

Spooner

Close