Skip to content
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

fix findMax for arrays with duplicates #1025

Merged
merged 3 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions addons/arrays/fnc_findMax.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ SCRIPT(findMax);

if !(_array isEqualTypeAll 0) exitWith {nil};

private _max = selectMax _array;
[_max, _array find _max]
private _reverse = + _array;
reverse _reverse;

private _max = selectMax _reverse;
[_max, count _array - (_reverse find _max) - 1]
2 changes: 1 addition & 1 deletion addons/arrays/test_findMax.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ TEST_OP(_result,isEqualTo,_expected,_fn);

// Test unordered array with duplicate max values
_result = [2, 15, 15, -3, -3] call CBA_fnc_findMax;
_expected = [15, 1];
_expected = [15, 2];
TEST_OP(_result,isEqualTo,_expected,_fn);

// Test invalid parameter array with bool
Expand Down