-
Notifications
You must be signed in to change notification settings - Fork 148
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
improve 'CBA_fnc_sortNestedArray' #380
Conversation
|
||
{ | ||
_array set [_forEachIndex, _helperArray select _forEachIndex select 1]; | ||
} forEach _array; |
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.
Could do:
{
_array set [_forEachIndex, _x select 1];
} forEach _helperArray;
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 = _helperArray apply {_x select 1};
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.
apply
is 1.56, so it won't work with the linux builds that are on 1.54(iirc).
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.
It would have been so beautiful.
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.
CBA_fnc_sortNestedArray
originally modified the array by reference, which means select
and apply
cannot be used. Even if you reassign the new array to the previous variable, it wouldnt behave the same.
blah = [0];
player setVariable ["blah", _blah];
blah set [0, 1];
player getVariable "blah";
-> 1
vs.
blah = [0];
player setVariable ["blah", _blah];
blah = blah apply {1};
player getVariable "blah";
-> 0
This is why select
, apply
and arrayIntersect
are not as versatile as they could've been...
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.
Creating a new array is kind of industry standard though. And I'm happy BIS used that approach.
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.
This function defies the standard, but we should go with bwc always.
_index: integer - sub array item index to be sorted on | ||
_array - Nested array to be sorted <ARRAY> | ||
_index - Sub array item index to be sorted on <NUMBER> | ||
_order - true: ascending, false: descending (optional: true) <BOOLEAN> |
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.
Should the "optional: true" comment mean that 1) it is optional and 2) the default is "true"? In that case,
(optional, default: true)
would be easier to understand.
CBA_fnc_sortNestedArray
use SQFs nativesort
commandBIS_fnc_sortBy
is using the same method now