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

x/ayonli_jsext/uint8array/index.ts>compare

A JavaScript extension package for building strong and modern applications.
Latest
function compare
import { compare } from "https://deno.land/x/ayonli_jsext@v0.9.72/uint8array/index.ts";

Like Buffer.compare but for native Uint8Array.

Examples

Example 1

import { compare } from "@ayonli/jsext/bytes";

const arr1 = new Uint8Array([1, 2, 3]);
const arr2 = new Uint8Array([1, 2, 4]);
const arr3 = new Uint8Array([1, 2, 3, 4]);
const arr4 = new Uint8Array([1, 2, 3]);
const arr5 = new Uint8Array([1, 2]);

console.log(compare(arr1, arr2)); // -1
console.log(compare(arr1, arr3)); // -1
console.log(compare(arr1, arr4)); // 0
console.log(compare(arr1, arr5)); // 1

Parameters

arr1: Uint8Array
arr2: Uint8Array

Returns

-1 | 0 | 1