( items: readonly T[], isComplete: (item: T) => boolean )
| 8 | * the predicate are never reordered past items that pass it. |
| 9 | */ |
| 10 | export function splitByContiguousPrefix<T>( |
| 11 | items: readonly T[], |
| 12 | isComplete: (item: T) => boolean |
| 13 | ): { staticItems: T[]; dynamicItems: T[] } { |
| 14 | let lastCompleteIndex = -1; |
| 15 | |
| 16 | for (let i = 0; i < items.length; i++) { |
| 17 | if (isComplete(items[i])) { |
| 18 | if (i === 0 || i === lastCompleteIndex + 1) { |
| 19 | lastCompleteIndex = i; |
| 20 | } else { |
| 21 | break; |
| 22 | } |
| 23 | } else { |
| 24 | break; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | return { |
| 29 | staticItems: items.slice(0, lastCompleteIndex + 1), |
| 30 | dynamicItems: items.slice(lastCompleteIndex + 1), |
| 31 | }; |
| 32 | } |
no outgoing calls
no test coverage detected