-
Notifications
You must be signed in to change notification settings - Fork 150
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
Add fnc_insert #542
Add fnc_insert #542
Conversation
You need to add it to CfgFunctions too. |
:picard:^2 |
if (_index >= _size || {_index < 0}) exitWith {[]}; | ||
|
||
_right = _array select [_index, _size]; | ||
_array deleteRange [_index, _size]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_array resize _index;
private _size = count _array; | ||
if (_index >= _size || {_index < 0}) exitWith {[]}; | ||
|
||
_right = _array select [_index, _size]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing private
params ["_array", "_index", "_element"]; | ||
|
||
private _size = count _array; | ||
if (_index >= _size || {_index < 0}) exitWith {[]}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[[], 1, "test"] call CBA_fnc_insert
should report
[nil, "test"]
imo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So just exitWith {}
or exitWith {nil}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the line is needed at all and can be removed.
Maybe keep the < 0
check, but the function doesn't do input validation anyway, so you might as well cut that too.
If we'd replace |
There exists /************************************************************
Array Insert
Author: Andrew Barron, optimised by Killzone_Kid
Parameters: [base array, insert array, index]
Returs: [array]
Inserts the elements of one array into another, at a specified
index.
Neither arrays are touched by reference, a new array is returned.
Example1: [[0,1,2,3,4], ["a","b","c"], 1] call BIS_fnc_arrayInsert
Returns: [0,"a","b","c",1,2,3,4]
Example2: [[1,2],[3,4],5] call BIS_fnc_arrayInsert
Returns: [1,2,<null>,<null>,<null>,3,4]
************************************************************/
/// --- validate general input
#include "..\paramsCheck.inc"
#define arr [[],[],0]
paramsCheck(_this,isEqualTypeParams,arr)
params ["_arr1", "_arr2", "_index"];
if (_index < 0) exitWith {_arr1};
private _size1 = count _arr1;
if (_index >= _size1) then {
_arr1 = +_arr1;
_arr1 resize _index;
};
(_arr1 select [0, _index]) + _arr2 + (_arr1 select [_index, _size1]) Differences:
We now have to think about:
|
@654wak654 Sorry for the delay. Can you add a unit test file for this? Would've to be added here: |
When merged this pull request will: