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 CBA_fnc_findMin, improve CBA_fnc_findMax #207

Merged
merged 3 commits into from
Dec 2, 2015
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
21 changes: 8 additions & 13 deletions addons/arrays/fnc_findMax.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Parameters:

Example:
(begin example)
_result = [_array] call CBA_fnc_findMax
_result = [0,4,3,-2] call CBA_fnc_findMax
(end)

Returns:
Expand All @@ -18,23 +18,18 @@ Returns:
nil on failure

Author:
joko // Jonas
joko // Jonas, commy2

---------------------------------------------------------------------------- */
#include "script_component.hpp"
SCRIPT(findMax);

if (!IS_ARRAY(_this)) exitWith {nil};
if (_this isEqualTo []) exitWith {nil};
[_this] params [["_array", [], [[]]]];

params ["_max"];
if !(_array isEqualTypeAll 0) exitWith {nil};

private _index = 0;
private _arraySorted = + _array;
_arraySorted sort false; // false - descending
_arraySorted params ["_max"];

{
if (isNil "_x" || {(typeName _x) != (typeName 0)}) exitWith {_max = nil; _index = nil;};
if (_max < _x) then {_max = _x; _index = _forEachIndex};
} forEach _this;

if (isNil "_max") exitWith {nil};
[_max, _index] // Return
[_max, _array find _max]
21 changes: 8 additions & 13 deletions addons/arrays/fnc_findMin.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Parameters:

Example:
(begin example)
_result = [_array] call CBA_fnc_findMin
_result = [0,4,3,-2] call CBA_fnc_findMin
(end)

Returns:
Expand All @@ -18,23 +18,18 @@ Returns:
nil on failure

Author:
joko // Jonas
joko // Jonas, commy2

---------------------------------------------------------------------------- */
#include "script_component.hpp"
SCRIPT(findMin);

if (!IS_ARRAY(_this)) exitWith {nil};
if (_this isEqualTo []) exitWith {nil};
[_this] params [["_array", [], [[]]]];

params ["_min"];
if !(_array isEqualTypeAll 0) exitWith {nil};

private _index = 0;
private _arraySorted = + _array;
_arraySorted sort true; // true - ascending
_arraySorted params ["_min"];

{
if (isNil "_x" || {(typeName _x) != (typeName 0)}) exitWith {_max = nil; _index = nil;};
if (_min > _x) then {_min = _x; _index = _forEachIndex};
} forEach _this;

if (isNil "_max") exitWith {nil};
[_min, _index] // Return
[_min, _array find _min]