cmpUint8Array2.js 800 B

123456789101112131415161718192021222324
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.cmpUint8Array2 = void 0;
  4. /**
  5. * Compares two `Uint8Arrays` byte-by-byte. Returns a negative number if `a` is
  6. * less than `b`, a positive number if `a` is greater than `b`, or 0 if `a` is
  7. * equal to `b`.
  8. *
  9. * @returns A negative number if a is less than b, a positive number if a is
  10. * greater than b, or 0 if a is equal to b.
  11. */
  12. const cmpUint8Array2 = (a, b) => {
  13. const len1 = a.length;
  14. const len2 = b.length;
  15. const len = Math.min(len1, len2);
  16. for (let i = 0; i < len; i++) {
  17. const diffChar = a[i] - b[i];
  18. if (diffChar !== 0)
  19. return diffChar;
  20. }
  21. return len1 - len2;
  22. };
  23. exports.cmpUint8Array2 = cmpUint8Array2;
  24. //# sourceMappingURL=cmpUint8Array2.js.map