UNPKG

3.24 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createCompareTextNumber = exports.createCompareText = void 0;
7
8var _string = require("../../utils/string");
9
10var _factory = require("../../utils/factory");
11
12var _algorithm = require("../../type/matrix/utils/algorithm14");
13
14var _algorithm2 = require("../../type/matrix/utils/algorithm13");
15
16var name = 'compareText';
17var dependencies = ['typed', 'matrix'];
18var createCompareText = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
19 var typed = _ref.typed,
20 matrix = _ref.matrix;
21 var algorithm13 = (0, _algorithm2.createAlgorithm13)({
22 typed: typed
23 });
24 var algorithm14 = (0, _algorithm.createAlgorithm14)({
25 typed: typed
26 });
27 /**
28 * Compare two strings lexically. Comparison is case sensitive.
29 * Returns 1 when x > y, -1 when x < y, and 0 when x == y.
30 *
31 * For matrices, the function is evaluated element wise.
32 *
33 * Syntax:
34 *
35 * math.compareText(x, y)
36 *
37 * Examples:
38 *
39 * math.compareText('B', 'A') // returns 1
40 * math.compareText('2', '10') // returns 1
41 * math.compare('2', '10') // returns -1
42 * math.compareNatural('2', '10') // returns -1
43 *
44 * math.compareText('B', ['A', 'B', 'C']) // returns [1, 0, -1]
45 *
46 * See also:
47 *
48 * equal, equalText, compare, compareNatural
49 *
50 * @param {string | Array | DenseMatrix} x First string to compare
51 * @param {string | Array | DenseMatrix} y Second string to compare
52 * @return {number | Array | DenseMatrix} Returns the result of the comparison:
53 * 1 when x > y, -1 when x < y, and 0 when x == y.
54 */
55
56 var compareText = typed(name, {
57 'any, any': _string.compareText,
58 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
59 return algorithm13(x, y, _string.compareText);
60 },
61 'Array, Array': function ArrayArray(x, y) {
62 // use matrix implementation
63 return compareText(matrix(x), matrix(y)).valueOf();
64 },
65 'Array, Matrix': function ArrayMatrix(x, y) {
66 // use matrix implementation
67 return compareText(matrix(x), y);
68 },
69 'Matrix, Array': function MatrixArray(x, y) {
70 // use matrix implementation
71 return compareText(x, matrix(y));
72 },
73 'DenseMatrix, any': function DenseMatrixAny(x, y) {
74 return algorithm14(x, y, _string.compareText, false);
75 },
76 'any, DenseMatrix': function anyDenseMatrix(x, y) {
77 return algorithm14(y, x, _string.compareText, true);
78 },
79 'Array, any': function ArrayAny(x, y) {
80 // use matrix implementation
81 return algorithm14(matrix(x), y, _string.compareText, false).valueOf();
82 },
83 'any, Array': function anyArray(x, y) {
84 // use matrix implementation
85 return algorithm14(matrix(y), x, _string.compareText, true).valueOf();
86 }
87 });
88 return compareText;
89});
90exports.createCompareText = createCompareText;
91var createCompareTextNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed'], function (_ref2) {
92 var typed = _ref2.typed;
93 return typed(name, {
94 'any, any': _string.compareText
95 });
96});
97exports.createCompareTextNumber = createCompareTextNumber;
\No newline at end of file