simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

compareText.js (3198B)


      1 "use strict";
      2 
      3 Object.defineProperty(exports, "__esModule", {
      4   value: true
      5 });
      6 exports.createCompareTextNumber = exports.createCompareText = void 0;
      7 
      8 var _string = require("../../utils/string.js");
      9 
     10 var _factory = require("../../utils/factory.js");
     11 
     12 var _algorithm = require("../../type/matrix/utils/algorithm14.js");
     13 
     14 var _algorithm2 = require("../../type/matrix/utils/algorithm13.js");
     15 
     16 var name = 'compareText';
     17 var dependencies = ['typed', 'matrix'];
     18 var 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   return 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 this(matrix(x), matrix(y)).valueOf();
     64     },
     65     'Array, Matrix': function ArrayMatrix(x, y) {
     66       // use matrix implementation
     67       return this(matrix(x), y);
     68     },
     69     'Matrix, Array': function MatrixArray(x, y) {
     70       // use matrix implementation
     71       return this(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 });
     89 exports.createCompareText = createCompareText;
     90 var createCompareTextNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed'], function (_ref2) {
     91   var typed = _ref2.typed;
     92   return typed(name, {
     93     'any, any': _string.compareText
     94   });
     95 });
     96 exports.createCompareTextNumber = createCompareTextNumber;