* Remove and return the first element matching the predicate, scanning from * front to back. The gap is closed by shifting whichever side (front or back) * has fewer elements to move, so removals near either end are fast. * * @example Removing the first even number * ```ts * import
(predicate: (value: T, index: number) => boolean)
| 329 | * @returns The removed element, or `undefined` if no match was found. |
| 330 | */ |
| 331 | removeFirst(predicate: (value: T, index: number) => boolean): T | undefined { |
| 332 | const i = this.#findIndex(predicate); |
| 333 | if (i === -1) return undefined; |
| 334 | return this.#removeAtUnchecked(i); |
| 335 | } |
| 336 | |
| 337 | /** |
| 338 | * Remove and return the element at the given index (0-based from front). |
no test coverage detected