MCPcopy Create free account
hub / github.com/denoland/std / removeFirst

Method removeFirst

data_structures/deque.ts:331–335  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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).

Callers 2

onAbortMethod · 0.80
deque_test.tsFile · 0.80

Calls 2

#findIndexMethod · 0.95
#removeAtUncheckedMethod · 0.95

Tested by

no test coverage detected