compareText.js (2839B)
1 import { compareText as _compareText } from '../../utils/string.js'; 2 import { factory } from '../../utils/factory.js'; 3 import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14.js'; 4 import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13.js'; 5 var name = 'compareText'; 6 var dependencies = ['typed', 'matrix']; 7 export var createCompareText = /* #__PURE__ */factory(name, dependencies, _ref => { 8 var { 9 typed, 10 matrix 11 } = _ref; 12 var algorithm13 = createAlgorithm13({ 13 typed 14 }); 15 var algorithm14 = createAlgorithm14({ 16 typed 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 47 return typed(name, { 48 'any, any': _compareText, 49 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) { 50 return algorithm13(x, y, _compareText); 51 }, 52 'Array, Array': function ArrayArray(x, y) { 53 // use matrix implementation 54 return this(matrix(x), matrix(y)).valueOf(); 55 }, 56 'Array, Matrix': function ArrayMatrix(x, y) { 57 // use matrix implementation 58 return this(matrix(x), y); 59 }, 60 'Matrix, Array': function MatrixArray(x, y) { 61 // use matrix implementation 62 return this(x, matrix(y)); 63 }, 64 'DenseMatrix, any': function DenseMatrixAny(x, y) { 65 return algorithm14(x, y, _compareText, false); 66 }, 67 'any, DenseMatrix': function anyDenseMatrix(x, y) { 68 return algorithm14(y, x, _compareText, true); 69 }, 70 'Array, any': function ArrayAny(x, y) { 71 // use matrix implementation 72 return algorithm14(matrix(x), y, _compareText, false).valueOf(); 73 }, 74 'any, Array': function anyArray(x, y) { 75 // use matrix implementation 76 return algorithm14(matrix(y), x, _compareText, true).valueOf(); 77 } 78 }); 79 }); 80 export var createCompareTextNumber = /* #__PURE__ */factory(name, ['typed'], _ref2 => { 81 var { 82 typed 83 } = _ref2; 84 return typed(name, { 85 'any, any': _compareText 86 }); 87 });