UNPKG

@extra-array/symmetric-difference

Version:

Gives values not present in both arrays.

64 lines (48 loc) 1.99 kB
Gives values not present in both arrays. [:package:](https://www.npmjs.com/package/@extra-array/symmetric-difference) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/symmetric-difference) [:vhs:](https://asciinema.org/a/339833) [:moon:](https://www.npmjs.com/package/@extra-array/symmetric-difference.min) [:scroll:](https://unpkg.com/@extra-array/symmetric-difference/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > Similar: [union], [intersection], [difference], [symmetricDifference]. > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array <br> ```javascript array.symmetricDifference(x, y, [fc], [fm]); // x: an array // y: another array // fc: compare function (a, b) // fm: map function (v, i, x) ``` > :stopwatch: Compare function => O(n²). ```javascript const array = require("extra-array"); var x = [1, 2, 3, 4]; var y = [3, 4, 5]; array.symmetricDifference(x, y); // [ 1, 2, 5 ] var y = [-3, -4, -5]; array.symmetricDifference(x, y); // [ // 1, 2, 3, 4, // -3, -4, -5 // ] array.symmetricDifference(x, y, (a, b) => Math.abs(a) - Math.abs(b)); // [ 1, 2, -5 ] array.symmetricDifference(x, y, null, v => Math.abs(v)); // [ 1, 2, -5 ] ``` <br> <br> ## References - [Data.List.\\: Haskell](https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:-92--92-) - [Data.Set.difference: Haskell](http://hackage.haskell.org/package/containers-0.6.2.1/docs/Data-Set.html#v:difference) - [Set.difference: Python](https://www.programiz.com/python-programming/methods/set/difference) [union]: https://github.com/nodef/extra-array/wiki/union [intersection]: https://github.com/nodef/extra-array/wiki/intersection [difference]: https://github.com/nodef/extra-array/wiki/difference [symmetricDifference]: https://github.com/nodef/extra-array/wiki/symmetricDifference