MCPcopy
hub / github.com/tldraw/tldraw / maxBy

Function maxBy

packages/utils/src/lib/array.ts:159–170  ·  view source on GitHub ↗
(arr: readonly T[], fn: (item: T) => number)

Source from the content-addressed store, hash-verified

157 * @internal
158 */
159export function maxBy<T>(arr: readonly T[], fn: (item: T) => number): T | undefined {
160 let max: T | undefined
161 let maxVal: number = -Infinity
162 for (const item of arr) {
163 const val = fn(item)
164 if (val > maxVal) {
165 max = item
166 maxVal = val
167 }
168 }
169 return max
170}
171
172/**
173 * Split an array into two arrays based on a predicate function.

Callers 2

array.test.tsFile · 0.90
getCollaboratorsMethod · 0.90

Calls 1

fnFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…