Page MenuHomeFeedback Tracker

Error in BIS_fnc_arrayUnShift
New, WishlistPublic

Description

The function does not work according to the comment header: “This function adds an element to the beginning of an array and returns the array.” Furthermore this is stated in the comment header:
"Example:
array = [2,3,4]
[array, 1] call BIS_fnc_ArrayUnshift
array is now [1,2,3,4]"

This is not true. The actual result is: [1,3,2]

Details

Legacy ID
341194080
Severity
None
Resolution
Open
Reproducibility
Always
Category
Scripting
Steps To Reproduce

array = [2,3,4]
[array, 1] call BIS_fnc_ArrayUnshift

Additional Information

//This is how to add an element to the beginning of an array:

private ["_array", "_i"];

// Parameters: [array, element]
_array = _this select 0;

// Loop through the array, from right to left, and move everything one step to the right
for "_i" from (count _array) - 1 to 0 step -1 do
{

_array set [_i + 1, _array select _i];

};

//set first element
_array set [0, _this select 1];
_array

Event Timeline

thor5viking edited Additional Information. (Show Details)
thor5viking set Category to Scripting.
thor5viking set Reproducibility to Always.
thor5viking set Severity to None.
thor5viking set Resolution to Open.
thor5viking set Legacy ID to 341194080.May 7 2016, 6:56 PM

With new commands you can simply

reverse arr;
arr pushBack el;
reverse arr;

Done

However when japa comes from holiday, maybe he can add pushFront? It is a cpp method so why reinvent a wheel?