UNPKG

@extra-array/difference

Version:

Gives values of array not present in another.

65 lines (49 loc) 2.16 kB
Gives values of array not present in another. [:package:](https://www.npmjs.com/package/@extra-array/difference) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/difference) [:vhs:](https://asciinema.org/a/332038) [:moon:](https://www.npmjs.com/package/@extra-array/difference.min) [:scroll:](https://unpkg.com/@extra-array/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.difference(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, 5]; var y = [2, 4]; array.difference(x, y); // [ 1, 3, 5 ] var y = [-2, -4]; array.difference(x, y); // [ 1, 2, 3, 4, 5 ] array.difference(x, y, (a, b) => Math.abs(a) - Math.abs(b)); // [ 1, 3, 5 ] array.difference(x, y, null, v => Math.abs(v)); // [ 1, 3, 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) - [_.difference: lodash](https://lodash.com/docs/4.17.15#difference) - [_.differenceBy: lodash](https://lodash.com/docs/4.17.15#differenceBy) - [_.differenceWith: lodash](https://lodash.com/docs/4.17.15#differenceWith) - [Array.remove: sugarjs](https://sugarjs.com/docs/#/Array/remove) [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