Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/discord_rpc_deno/deps.ts>bytes.includesNeedle

port of @xhayper/discord-rpc to deno
Latest
function bytes.includesNeedle
import { bytes } from "https://deno.land/x/discord_rpc_deno@v1.1.4/deps.ts";
const { includesNeedle } = bytes;

Determines whether the source array contains the needle array.

The complexity of this function is O(source.length * needle.length).

Examples

Basic usage

import { includesNeedle } from "https://deno.land/std@0.224.0/bytes/includes_needle.ts";

const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
const needle = new Uint8Array([1, 2]);

includesNeedle(source, needle); // true

Start index

import { includesNeedle } from "https://deno.land/std@0.224.0/bytes/includes_needle.ts";

const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
const needle = new Uint8Array([1, 2]);

includesNeedle(source, needle, 6); // false

The search will start at the specified index in the source array.

Parameters

source: Uint8Array

Source array to check.

needle: Uint8Array

Needle array to check for.

optional
start = [UNSUPPORTED]

Start index in the source array to begin the search. Defaults to 0.

Returns

boolean

true if the source array contains the needle array, false otherwise.