1 | Gives values not present in both arrays.
|
2 | [:package:](https://www.npmjs.com/package/@extra-array/symmetric-difference)
|
3 | [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
|
4 | [:running:](https://npm.runkit.com/@extra-array/symmetric-difference)
|
5 | [:vhs:](https://asciinema.org/a/339833)
|
6 | [:moon:](https://www.npmjs.com/package/@extra-array/symmetric-difference.min)
|
7 | [:scroll:](https://unpkg.com/@extra-array/symmetric-difference/)
|
8 | [:newspaper:](https://nodef.github.io/extra-array/)
|
9 | [:blue_book:](https://github.com/nodef/extra-array/wiki/)
|
10 |
|
11 | > Similar: [union], [intersection], [difference], [symmetricDifference].
|
12 |
|
13 | > This is part of package [extra-array].
|
14 |
|
15 | [extra-array]: https://www.npmjs.com/package/extra-array
|
16 |
|
17 | <br>
|
18 |
|
19 | ```javascript
|
20 | array.symmetricDifference(x, y, [fc], [fm]);
|
21 | // x: an array
|
22 | // y: another array
|
23 | // fc: compare function (a, b)
|
24 | // fm: map function (v, i, x)
|
25 | ```
|
26 | > :stopwatch: Compare function => O(n²).
|
27 |
|
28 | ```javascript
|
29 | const array = require("extra-array");
|
30 |
|
31 | var x = [1, 2, 3, 4];
|
32 | var y = [3, 4, 5];
|
33 | array.symmetricDifference(x, y);
|
34 | // [ 1, 2, 5 ]
|
35 |
|
36 | var y = [-3, -4, -5];
|
37 | array.symmetricDifference(x, y);
|
38 | // [
|
39 | // 1, 2, 3, 4,
|
40 | // -3, -4, -5
|
41 | // ]
|
42 |
|
43 | array.symmetricDifference(x, y, (a, b) => Math.abs(a) - Math.abs(b));
|
44 | // [ 1, 2, -5 ]
|
45 |
|
46 | array.symmetricDifference(x, y, null, v => Math.abs(v));
|
47 | // [ 1, 2, -5 ]
|
48 | ```
|
49 |
|
50 | <br>
|
51 | <br>
|
52 |
|
53 |
|
54 | ## References
|
55 |
|
56 | - [Data.List.\\: Haskell](https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:-92--92-)
|
57 | - [Data.Set.difference: Haskell](http://hackage.haskell.org/package/containers-0.6.2.1/docs/Data-Set.html#v:difference)
|
58 | - [Set.difference: Python](https://www.programiz.com/python-programming/methods/set/difference)
|
59 |
|
60 | [union]: https://github.com/nodef/extra-array/wiki/union
|
61 | [intersection]: https://github.com/nodef/extra-array/wiki/intersection
|
62 | [difference]: https://github.com/nodef/extra-array/wiki/difference
|
63 | [symmetricDifference]: https://github.com/nodef/extra-array/wiki/symmetricDifference
|