(items: T[], target: string, key: (item: T) => string)
| 39 | } |
| 40 | |
| 41 | function search<T>(items: T[], target: string, key: (item: T) => string) { |
| 42 | let left = 0 |
| 43 | let right = items.length - 1 |
| 44 | while (left <= right) { |
| 45 | const middle = Math.floor((left + right) / 2) |
| 46 | const value = key(items[middle]) |
| 47 | if (value === target) return { found: true, index: middle } |
| 48 | if (value < target) left = middle + 1 |
| 49 | else right = middle - 1 |
| 50 | } |
| 51 | return { found: false, index: left } |
| 52 | } |
| 53 | |
| 54 | export const { |
| 55 | context: SyncContext, |
no test coverage detected