Returns the smallest value from a list.
min([1, 2, 3, 4]); // => 1min([{ num: 1 }, { num: 2 }], (x) => x.num); // => { num: 1 }
npx atmx add helper min
Copy and paste the following method into @/utils/helpers/undefined.ts:
@/utils/helpers/undefined.ts
/*** Returns the smallest value from a list.** @example* min([1, 2, 3, 4]) // => 1* min([{ num: 1 }, { num: 2 }], x => x.num) // => { num: 1 }*/export function min(array: readonly [number, ...number[]]): number;export function min(array: readonly number[]): number | null;export function min<T>(array: readonly T[],getter: (item: T) => number,): T | null;export function min<T>(array: readonly T[],getter?: (item: T) => number,): T | null {if (!array || (array.length ?? 0) === 0) {return null;}const get = getter ?? ((v: any) => v);return array.reduce((a, b) => (get(a) < get(b) ? a : b));}