setSymDifference.js (1880B)
1 "use strict"; 2 3 Object.defineProperty(exports, "__esModule", { 4 value: true 5 }); 6 exports.createSetSymDifference = void 0; 7 8 var _array = require("../../utils/array.js"); 9 10 var _factory = require("../../utils/factory.js"); 11 12 var name = 'setSymDifference'; 13 var dependencies = ['typed', 'size', 'concat', 'subset', 'setDifference', 'Index']; 14 var createSetSymDifference = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) { 15 var typed = _ref.typed, 16 size = _ref.size, 17 concat = _ref.concat, 18 subset = _ref.subset, 19 setDifference = _ref.setDifference, 20 Index = _ref.Index; 21 22 /** 23 * Create the symmetric difference of two (multi)sets. 24 * Multi-dimension arrays will be converted to single-dimension arrays before the operation. 25 * 26 * Syntax: 27 * 28 * math.setSymDifference(set1, set2) 29 * 30 * Examples: 31 * 32 * math.setSymDifference([1, 2, 3, 4], [3, 4, 5, 6]) // returns [1, 2, 5, 6] 33 * math.setSymDifference([[1, 2], [3, 4]], [[3, 4], [5, 6]]) // returns [1, 2, 5, 6] 34 * 35 * See also: 36 * 37 * setUnion, setIntersect, setDifference 38 * 39 * @param {Array | Matrix} a1 A (multi)set 40 * @param {Array | Matrix} a2 A (multi)set 41 * @return {Array | Matrix} The symmetric difference of two (multi)sets 42 */ 43 return typed(name, { 44 'Array | Matrix, Array | Matrix': function ArrayMatrixArrayMatrix(a1, a2) { 45 if (subset(size(a1), new Index(0)) === 0) { 46 // if any of them is empty, return the other one 47 return (0, _array.flatten)(a2); 48 } else if (subset(size(a2), new Index(0)) === 0) { 49 return (0, _array.flatten)(a1); 50 } 51 52 var b1 = (0, _array.flatten)(a1); 53 var b2 = (0, _array.flatten)(a2); 54 return concat(setDifference(b1, b2), setDifference(b2, b1)); 55 } 56 }); 57 }); 58 exports.createSetSymDifference = createSetSymDifference;