Created
September 6, 2019 18:47
-
-
Save masautt/c64cebd8b3d4503d6a65cf2dce6370a3 to your computer and use it in GitHub Desktop.
How to find the intersection of 2 arrays in JavaScript?
This file contains hidden or 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
function findIntersection(arr1, arr2) { | |
return arr1.filter(value => arr2.includes(value)) | |
} | |
console.log(findIntersection(["M","A", "R", "E", "K"], ["M","A", "S", "A", "T", "T"])) // --> [ 'M', 'A' ] | |
// https://stackoverflow.com/questions/1885557/simplest-code-for-array-intersection-in-javascript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment