compareText.js 1.7 KB

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