UNPKG

uint8arrays

Version:

Utility functions to make dealing with Uint8Arrays easier

25 lines (20 loc) 408 B
/** * Can be used with Array.sort to sort and array with Uint8Array entries */ export function compare (a: Uint8Array, b: Uint8Array): number { for (let i = 0; i < a.byteLength; i++) { if (a[i] < b[i]) { return -1 } if (a[i] > b[i]) { return 1 } } if (a.byteLength > b.byteLength) { return 1 } if (a.byteLength < b.byteLength) { return -1 } return 0 }