UNPKG

@extra-array/union-update

Version:

Gives values present in any array.

69 lines (53 loc) 2.15 kB
Gives values present in any array. [:package:](https://www.npmjs.com/package/@extra-array/union-update) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/union-update) [:vhs:](https://asciinema.org/a/332147) [:moon:](https://www.npmjs.com/package/@extra-array/union-update.min) [:scroll:](https://unpkg.com/@extra-array/union-update/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > Alternatives: [union], [union$].<br> > Similar: [union], [intersection], [difference], [symmetricDifference]. > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array <br> ```javascript array.union$(x, y, [fc], [fm]); // x: an array (updated) // y: another array // fc: compare function (a, b) // fm: map function (v, i, x) // → x ``` > :stopwatch: Compare function => O(n²). ```javascript const array = require("extra-array"); var x = [1, 2, 3, 4]; var y = [2, 3, 5]; array.union$(x, y); // [ 1, 2, 3, 4, 5 ] x; // [ 1, 2, 3, 4, 5 ] var x = [1, 2, 3, 4]; var y = [-2, -3, -5]; array.union$(x, y, (a, b) => Math.abs(a) - Math.abs(b)); // [ 1, 2, 3, 4, -5 ] var x = [1, 2, 3, 4]; array.union$(x, y, null, v => Math.abs(v)); // [ 1, 2, 3, 4, -5 ] ``` <br> <br> ## References - [Data.Set.union: Haskell](http://hackage.haskell.org/package/containers-0.6.2.1/docs/Data-Set.html#v:union) - [Set.union: Python](https://www.programiz.com/python-programming/methods/set/union) - [_.union: lodash](https://lodash.com/docs/4.17.15#union) - [_.unionBy: lodash](https://lodash.com/docs/4.17.15#unionBy) - [_.unionWith: lodash](https://lodash.com/docs/4.17.15#unionWith) - [Array.union: sugarjs](https://sugarjs.com/docs/#/Array/union) [union]: https://github.com/nodef/extra-array/wiki/union [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