max
math
Computes the maximum value of array.
Installation
Import
import { max } from '@tulx/utils';Source Code
Implementation
/**
* Computes the maximum value of array.
*
* @param array - The array to iterate over.
* @returns Returns the maximum value.
*
* @example
* ```ts
* max([4, 2, 8, 6]); // 8
* max([]); // undefined
* ```
*/
export function max(array: readonly number[]): number | undefined {
if (array.length === 0) {
return undefined;
}
return Math.max(...array);
}
Example
import { max } from '@tulx/utils';
max([4, 2, 8, 6]); // 8
max([]); // undefinedRelated Functions
add
Adds two numbers.
ceil
Computes number rounded up to precision.
divide
Divide two numbers.
floor
Computes number rounded down to precision.
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.
mean
Computes the mean of the values in array.