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

Method pushFront

data_structures/deque.ts:248–260  ·  view source on GitHub ↗

* Prepend one or more values to the front of the deque. Values are inserted * in argument order, so `pushFront(1, 2, 3)` results in front-to-back order * `[1, 2, 3, ...existing]`. * * @example Pushing values to the front * ```ts * import { Deque } from "@std/data-structures/deque";

(value: T, ...rest: T[])

Source from the content-addressed store, hash-verified

246 * @returns The new length of the deque.
247 */
248 pushFront(value: T, ...rest: T[]): number {
249 for (let i = rest.length - 1; i >= 0; i--) {
250 this.#maybeGrow();
251 this.#head = (this.#head - 1) & this.#mask;
252 this.#buffer[this.#head] = rest[i]!;
253 this.#length++;
254 }
255 this.#maybeGrow();
256 this.#head = (this.#head - 1) & this.#mask;
257 this.#buffer[this.#head] = value;
258 this.#length++;
259 return this.#length;
260 }
261
262 /**
263 * Remove and return the back element, or `undefined` if the deque is empty.

Callers 1

deque_test.tsFile · 0.80

Calls 1

#maybeGrowMethod · 0.95

Tested by

no test coverage detected