UNPKG

2.92 kBJavaScriptView Raw
1import { compareText as _compareText } from '../../utils/string';
2import { factory } from '../../utils/factory';
3import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14';
4import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13';
5var name = 'compareText';
6var dependencies = ['typed', 'matrix'];
7export var createCompareText =
8/* #__PURE__ */
9factory(name, dependencies, function (_ref) {
10 var typed = _ref.typed,
11 matrix = _ref.matrix;
12 var algorithm13 = createAlgorithm13({
13 typed: typed
14 });
15 var algorithm14 = createAlgorithm14({
16 typed: 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 var compareText = 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 compareText(matrix(x), matrix(y)).valueOf();
55 },
56 'Array, Matrix': function ArrayMatrix(x, y) {
57 // use matrix implementation
58 return compareText(matrix(x), y);
59 },
60 'Matrix, Array': function MatrixArray(x, y) {
61 // use matrix implementation
62 return compareText(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 return compareText;
80});
81export var createCompareTextNumber =
82/* #__PURE__ */
83factory(name, ['typed'], function (_ref2) {
84 var typed = _ref2.typed;
85 return typed(name, {
86 'any, any': _compareText
87 });
88});
\No newline at end of file