1 | 'use strict'
|
2 |
|
3 | const flatten = require('../../utils/array').flatten
|
4 |
|
5 | function factory (type, config, load, typed) {
|
6 | const MatrixIndex = load(require('../../type/matrix/MatrixIndex'))
|
7 | const concat = load(require('../matrix/concat'))
|
8 | const size = load(require('../matrix/size'))
|
9 | const subset = load(require('../matrix/subset'))
|
10 | const setDifference = load(require('../set/setDifference'))
|
11 |
|
12 | |
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | const setSymDifference = typed('setSymDifference', {
|
34 | 'Array | Matrix, Array | Matrix': function (a1, a2) {
|
35 | if (subset(size(a1), new MatrixIndex(0)) === 0) {
|
36 | return flatten(a2)
|
37 | } else if (subset(size(a2), new MatrixIndex(0)) === 0) {
|
38 | return flatten(a1)
|
39 | }
|
40 | const b1 = flatten(a1)
|
41 | const b2 = flatten(a2)
|
42 | return concat(setDifference(b1, b2), setDifference(b2, b1))
|
43 | }
|
44 | })
|
45 |
|
46 | return setSymDifference
|
47 | }
|
48 |
|
49 | exports.name = 'setSymDifference'
|
50 | exports.factory = factory
|