Skip to content

max

计算传入数组的最大值,支持通过可选参数getter提取数值(或直接使用数组元素的数值)。

gettergetByPath函数的字段路径,或者回调函数,用于提取数值。

Added in v0.0.1

Usage

ts
import { max } from 'parsnip-kit'

max([1, 2, 3, 4]) // 4

max([{ value: 10 }, { value: 20 }], item => item.value) // 20

max([{ score: 85 }, { score: 95 }], 'score') // 95

API

Type Parameter

ArgTypeDescription
T输入的数组元素类型

Arguments

ArgTypeOptionalDefaultDescription
dataT[]falseundefined输入的数组
getterstring | ((item: T, index: number, arr: T[]) => number)trueundefined用于从数组元素中提取数值

Returns

Type
number