typedash
Version:
modern, type-safe collection of utility functions
1 lines • 1.64 kB
Source Map (JSON)
{"version":3,"file":"max-2GsfVaI-.cjs","names":[],"sources":["../src/functions/max/max.ts"],"sourcesContent":["import type { Maybe } from '../../types';\n\n/**\n * Computes the maximum value of array. If array is empty or nil, `undefined` is returned.\n * @param array The array to iterate over.\n * @returns The maximum value in the array, or `undefined` if the array is empty or nil.\n */\nexport function max<T>(array: Maybe<readonly T[]>): number;\n/**\n * Computes the maximum value of array. If array is empty or nil, `undefined` is returned.\n * @param array The array to iterate over.\n * @param valueExtractor An optional function used to extract a numeric value from each element.\n * @returns The maximum value in the array, or `undefined` if the array is empty or nil.\n */\nexport function max<T>(\n array: Maybe<readonly T[]>,\n valueExtractor?: (value: T) => number\n): number;\n/**\n * Implementation for all overloads.\n * @param array The array to iterate over.\n * @param valueExtractor The function used to extract a numeric value from each element.\n * @returns The maximum value in the array, or `undefined` if the array is empty or nil.\n */\nexport function max<T>(\n array: Maybe<readonly T[]>,\n valueExtractor: (value: T) => number = (value) => value as unknown as number\n): number | undefined {\n if (array == null || array.length === 0) {\n return undefined;\n }\n\n return Math.max(...array.map((element) => valueExtractor(element)));\n}\n"],"mappings":";;;;;;;;AAwBA,SAAgB,IACd,OACA,kBAAwC,UAAU,OAC9B;AACpB,KAAI,SAAS,QAAQ,MAAM,WAAW,EACpC;AAGF,QAAO,KAAK,IAAI,GAAG,MAAM,KAAK,YAAY,eAAe,QAAQ,CAAC,CAAC"}