maxBy (for BigInts) es-toolkit
Returns the element of an array whose derived BigInt value is the largest.
This function is available exclusively from es-toolkit/bigint to avoid potential conflicts with similar functions for other numeric types.
Usage
maxBy(items, getValue)
Use maxBy when the BigInts you want to compare are inside objects and you want the whole object back, not just the number. Pass a function that pulls the value out of each element.
When several elements tie for the largest value, the first one wins. getValue also receives the index and the whole array.
An empty array has no element to return, so it throws.
Parameters
The array of elements to search.
A function that returns the BigInt to compare by.
Returns
Returns the element with the largest derived BigInt. Returns the first of several elements that tie.
Throws
Throws a RangeError if the array is empty.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.