Created
June 28, 2019 12:20
-
-
Save inodaf/16a620c83ea6c897fa93988d1d9520a8 to your computer and use it in GitHub Desktop.
Find Intersection in Array
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
const intersection = (a, b) => | |
a.map(ai => b.filter(bi => bi === ai)).flat() | |
intersection(['banana', 'apple'], ['banana', 'mellon']) // ['banana'] | |
intersection(['banana', 'apple'], ['banana', 'mellon', 'apple']) // ['banana', 'apple'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment