You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.6 KiB
Markdown

4 years ago
# do-arrays-intersect
Checks only *whether* two given arrays intersect (ie. have values in common), but not *what* that intersection is exactly. This allows it to stop searching when it finds the first match, which can be much faster.
## License, donations, and other boilerplate
Licensed under either the [WTFPL](http://www.wtfpl.net/txt/copying/) or [CC0](https://creativecommons.org/publicdomain/zero/1.0/), at your choice. In practice, that means it's more or less public domain, and you can do whatever you want with it. Giving credit is *not* required, but still very much appreciated! I'd love to [hear from you](mailto:admin@cryto.net) if this module was useful to you.
Creating and maintaining open-source modules is a lot of work. A donation is also not required, but much appreciated! You can donate [here](http://cryto.net/~joepie91/donate.html).
## Example
```js
const doArraysIntersect = require("do-arrays-intersect");
let arrayA = [1, 3, 4, 6, 7, 8];
let arrayB = [2, 5, 6, 8, 9];
console.log(doArraysIntersect(arrayA, arrayB)); // true
let arrayC = [1, 3, 4, 6, 7, 8];
let arrayD = [2, 5, 9, 10, 11];
console.log(doArraysIntersect(arrayC, arrayD)); // false
```
## API
### doArraysIntersect(arrayA, arrayB)
Checks whether two arrays intersect. The equivalence function is `===`, and custom equivalence functions are not currently supported; please file an issue if you need this!
The order that you specify the arrays in, does not matter.
- __arrayA:__ The first array.
- __arrayB:__ The second array.
Returns a boolean indicating whether an intersection was found (`true`) or not (`false`).