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