(arr: readonly T[], fn: (item: T) => number)
| 124 | * @internal |
| 125 | */ |
| 126 | export 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. |
no test coverage detected
searching dependent graphs…