Returns the maximum value of the given array.
If duplicate values are present in the array, then the first match will be returned.
Related
Syntax
import { max } from '@opentf/std';
max<T>(
arr: T[] = [],
by: (val: T) => number = (x: T) => x as number
): T | null
Examples
max([]) //=> null
max([1, undefined, 2, null, 3]) //=> 3
max([1, 2, 3, 4, 5]) //=> 5
const arr = [
{
name: 'x',
age: 10,
},
{
name: 'y',
age: 16,
},
{
name: 'z',
age: 13,
},
{ name: 'y2', age: 16 },
];
max(arr, (o) => o.age))
//=>
// {
// name: 'y',
// age: 16,
// }