Created
June 2, 2018 23:31
-
-
Save mrchief/faa92bca9079eec382e83da5c24efb07 to your computer and use it in GitHub Desktop.
Simple array intersection check in ES6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Returns true if a intersects with b | |
* a is said to intersect with b if at least 1 element of a is present in b. | |
* e.g. | |
* intersects(['1', '2'], ['1', '3', '4']) // true | |
* intersects(['1', '2'], ['3', '4']) // false | |
*/ | |
export default (a, b) => a.some(k => b.indexOf(k) > -1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment