MCPcopy
hub / github.com/tldraw/tldraw / minBy

Function minBy

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

Source from the content-addressed store, hash-verified

124 * @internal
125 */
126export function minBy<T>(arr: readonly T[], fn: (item: T) => number): T | undefined {
127 let min: T | undefined
128 let minVal = Infinity
129 for (const item of arr) {
130 const val = fn(item)
131 if (val < minVal) {
132 min = item
133 minVal = val
134 }
135 }
136 return min
137}
138
139/**
140 * Find the item in an array with the maximum value according to a function.

Callers 3

array.test.tsFile · 0.90
StylePanelOpacityPickerFunction · 0.85

Calls 1

fnFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…