cmpUint8Array3.js 836 B

1234567891011121314151617181920212223242526
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.cmpUint8Array3 = void 0;
  4. /**
  5. * Compares two `Uint8Arrays`, first by length, then by each byte. Returns a
  6. * negative number if `a` is less than `b`, a positive number if `a` is greater
  7. * than `b`, or 0 if `a` is 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 cmpUint8Array3 = (a, b) => {
  13. const len1 = a.length;
  14. const len2 = b.length;
  15. const diff = len1 - len2;
  16. if (diff !== 0)
  17. return diff;
  18. for (let i = 0; i < len1; i++) {
  19. const diff = a[i] - b[i];
  20. if (diff !== 0)
  21. return diff;
  22. }
  23. return 0;
  24. };
  25. exports.cmpUint8Array3 = cmpUint8Array3;
  26. //# sourceMappingURL=cmpUint8Array3.js.map