* Check whether the deque contains a value, using * https://tc39.es/ecma262/#sec-samevaluezero | SameValueZero * comparison (like code Array.prototype.includes). * * @example Checking for membership * ```ts * import { Deque } from "@std/data-structures/deque"; * i
(value: T)
| 510 | * @returns `true` if the deque contains the value, otherwise `false`. |
| 511 | */ |
| 512 | includes(value: T): boolean { |
| 513 | const buf = this.#buffer; |
| 514 | const head = this.#head; |
| 515 | const len = this.#length; |
| 516 | const cap = this.#mask + 1; |
| 517 | const firstLen = Math.min(len, cap - head); |
| 518 | // SameValueZero: === for everything except NaN |
| 519 | for (let i = 0; i < firstLen; i++) { |
| 520 | const el = buf[head + i]; |
| 521 | if (el === value || (el !== el && value !== value)) return true; |
| 522 | } |
| 523 | const rem = len - firstLen; |
| 524 | for (let i = 0; i < rem; i++) { |
| 525 | const el = buf[i]; |
| 526 | if (el === value || (el !== el && value !== value)) return true; |
| 527 | } |
| 528 | return false; |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * Remove all elements and release the backing buffer. |
no test coverage detected