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

Method toArray

data_structures/deque.ts:603–614  ·  view source on GitHub ↗

* Return a shallow copy of the deque's contents as an array, in * front-to-back order. * * @example Converting to an array * ```ts * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([1, 2, 3]); *

()

Source from the content-addressed store, hash-verified

601 * @returns An array containing the deque's elements in order.
602 */
603 toArray(): T[] {
604 const buf = this.#buffer;
605 const head = this.#head;
606 const len = this.#length;
607 const cap = this.#mask + 1;
608 const result = new Array<T>(len);
609 const firstLen = Math.min(len, cap - head);
610 for (let i = 0; i < firstLen; i++) result[i] = buf[head + i] as T;
611 const rem = len - firstLen;
612 for (let i = 0; i < rem; i++) result[firstLen + i] = buf[i] as T;
613 return result;
614 }
615
616 /**
617 * Create a new deque from an array-like, iterable, or existing deque.

Callers 5

deque_test.tsFile · 0.45
fromMethod · 0.45

Calls 1

minMethod · 0.80

Tested by

no test coverage detected