Jump to content
Sign in to follow this  
davidoss

De- nesting arrays

Recommended Posts

Hi.

I want to ask you fellows if there are any function or command that could format passed nested arrays to un-nested one?

I have tried to write such thing but this iteration inside iteration breaking my brain.

_weapons = [["CUP_arifle_L85A2_SUSAT_Laser","Throw","Put"],["CUP_arifle_L85A2_Holo_laser","CUP_hgun_Colt1911","Throw","Put","CUP_Vector21Nite"],["CUP_arifle_L85A2_Holo_laser","Throw","Put","Binocular"]];


_weapons call {

_unnested = [];
{

_unnested pushBackUnique _x;

} forEach {_this select _x} forEach _this;
_unnested

};

Need to get:

["CUP_arifle_L85A2_SUSAT_Laser","Throw","Put","CUP_arifle_L85A2_Holo_laser","CUP_hgun_Colt1911","CUP_Vector21Nite","Binocular"];

Please help

Share this post


Link to post
Share on other sites

Not quite sure how you came to your weird forEach forEach syntax, but this should work:

_unnest = {

    params ["_input"];

    _output = [];

    {

        _nest = _x;

        {

            _output pushBackUnique _x;

        } foreach _nest;

    } foreach _input;

    _output
};

Cheers

Share this post


Link to post
Share on other sites

_weapons call {

_unnested = [];

{

    {

        _unnested pushBackUnique _x

    } foreach _x

} forEach _this;

_unnested

};

damn. Beaten by the elderly fellow.
  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×