rc-js-util
Version:
A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.
26 lines (22 loc) • 553 B
text/typescript
import { _Debug } from "../../debug/_debug.js";
/**
* @public
* Find the smallest number in an array, if the array is empty the return is Infinity.
*
* @remarks
* See {@link arrayMin}.
*/
export function arrayMin(numbers: ArrayLike<number>): number
{
let min = Infinity;
for (let i = 0, iEnd = numbers.length; i < iEnd; ++i)
{
const value = numbers[i];
_BUILD.DEBUG && _Debug.assert(value === value, "NaN not supported");
if (value < min)
{
min = value;
}
}
return min;
}