Created
December 5, 2019 23:11
-
-
Save frankiehayward/54a7acda32cf3bf7d78ddda118729348 to your computer and use it in GitHub Desktop.
This snippet can be used to return a list of elements that exist in both arrays by using a comparator function.
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
const intersectionWith = (a, b, comp) => a.filter(x => b.findIndex(y => comp(x, y)) !== -1); | |
intersectionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b)); // [1.5, 3, 0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment