deepEqual.js (2187B)
1 "use strict"; 2 3 Object.defineProperty(exports, "__esModule", { 4 value: true 5 }); 6 exports.createDeepEqual = void 0; 7 8 var _factory = require("../../utils/factory.js"); 9 10 var name = 'deepEqual'; 11 var dependencies = ['typed', 'equal']; 12 var createDeepEqual = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) { 13 var typed = _ref.typed, 14 equal = _ref.equal; 15 16 /** 17 * Test element wise whether two matrices are equal. 18 * The function accepts both matrices and scalar values. 19 * 20 * Strings are compared by their numerical value. 21 * 22 * Syntax: 23 * 24 * math.deepEqual(x, y) 25 * 26 * Examples: 27 * 28 * math.deepEqual(2, 4) // returns false 29 * 30 * a = [2, 5, 1] 31 * b = [2, 7, 1] 32 * 33 * math.deepEqual(a, b) // returns false 34 * math.equal(a, b) // returns [true, false, true] 35 * 36 * See also: 37 * 38 * equal, unequal 39 * 40 * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x First matrix to compare 41 * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} y Second matrix to compare 42 * @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} 43 * Returns true when the input matrices have the same size and each of their elements is equal. 44 */ 45 return typed(name, { 46 'any, any': function anyAny(x, y) { 47 return _deepEqual(x.valueOf(), y.valueOf()); 48 } 49 }); 50 /** 51 * Test whether two arrays have the same size and all elements are equal 52 * @param {Array | *} x 53 * @param {Array | *} y 54 * @return {boolean} Returns true if both arrays are deep equal 55 */ 56 57 function _deepEqual(x, y) { 58 if (Array.isArray(x)) { 59 if (Array.isArray(y)) { 60 var len = x.length; 61 62 if (len !== y.length) { 63 return false; 64 } 65 66 for (var i = 0; i < len; i++) { 67 if (!_deepEqual(x[i], y[i])) { 68 return false; 69 } 70 } 71 72 return true; 73 } else { 74 return false; 75 } 76 } else { 77 if (Array.isArray(y)) { 78 return false; 79 } else { 80 return equal(x, y); 81 } 82 } 83 } 84 }); 85 exports.createDeepEqual = createDeepEqual;