min
math
Computes the minimum value of array.
Installation
Import
import { min } from '@tulx/utils';Source Code
Implementation
/**
* Computes the minimum value of array.
*
* @param array - The array to iterate over.
* @returns Returns the minimum value.
*
* @example
* ```ts
* min([4, 2, 8, 6]); // 2
* min([]); // undefined
* ```
*/
export function min(array: readonly number[]): number | undefined {
if (array.length === 0) {
return undefined;
}
return Math.min(...array);
}
Example
import { min } from '@tulx/utils';
min([4, 2, 8, 6]); // 2
min([]); // undefinedRelated Functions
add
Adds two numbers.
ceil
Computes number rounded up to precision.
divide
Divide two numbers.
floor
Computes number rounded down to precision.
max
Computes the maximum value of array.
maxBy
This method is like max except that it accepts iteratee which is invoked for each element in array to generate the criterion by which the value is ranked.