Array
min

Returns the minimum value of the given array.

If duplicate values are present in the array, then the first match will be returned.

Related

Syntax

import { min } from '@opentf/std';
 
min<T>(
  arr: T[] = [],
  by: (val: T) => number = (x: T) => x as number
): T | null

Examples

max([]) //=> null
 
max([1, undefined, 2, null, 3]) //=> 1
 
min([1, 2, -3, 4, 5]) //=> -3
 
const arr = [
  {
    name: 'x',
    age: 10,
  },
  {
    name: 'x2',
    age: 10,
  },
  {
    name: 'y',
    age: 16,
  },
  {
    name: 'z',
    age: 13,
  },
  { name: 'y2', age: 16 },
];
min(arr, (f) => f.age)
//=> 
// {
//  name: 'x',
//  age: 10,
// }

Try