compareText.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { compareText as _compareText } from '../../utils/string.js';
  2. import { factory } from '../../utils/factory.js';
  3. import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
  4. var name = 'compareText';
  5. var dependencies = ['typed', 'matrix', 'concat'];
  6. _compareText.signature = 'any, any';
  7. export var createCompareText = /* #__PURE__ */factory(name, dependencies, _ref => {
  8. var {
  9. typed,
  10. matrix,
  11. concat
  12. } = _ref;
  13. var matrixAlgorithmSuite = createMatrixAlgorithmSuite({
  14. typed,
  15. matrix,
  16. concat
  17. });
  18. /**
  19. * Compare two strings lexically. Comparison is case sensitive.
  20. * Returns 1 when x > y, -1 when x < y, and 0 when x == y.
  21. *
  22. * For matrices, the function is evaluated element wise.
  23. *
  24. * Syntax:
  25. *
  26. * math.compareText(x, y)
  27. *
  28. * Examples:
  29. *
  30. * math.compareText('B', 'A') // returns 1
  31. * math.compareText('2', '10') // returns 1
  32. * math.compare('2', '10') // returns -1
  33. * math.compareNatural('2', '10') // returns -1
  34. *
  35. * math.compareText('B', ['A', 'B', 'C']) // returns [1, 0, -1]
  36. *
  37. * See also:
  38. *
  39. * equal, equalText, compare, compareNatural
  40. *
  41. * @param {string | Array | DenseMatrix} x First string to compare
  42. * @param {string | Array | DenseMatrix} y Second string to compare
  43. * @return {number | Array | DenseMatrix} Returns the result of the comparison:
  44. * 1 when x > y, -1 when x < y, and 0 when x == y.
  45. */
  46. return typed(name, _compareText, matrixAlgorithmSuite({
  47. elop: _compareText,
  48. Ds: true
  49. }));
  50. });
  51. export var createCompareTextNumber = /* #__PURE__ */factory(name, ['typed'], _ref2 => {
  52. var {
  53. typed
  54. } = _ref2;
  55. return typed(name, _compareText);
  56. });