Skip to content

Instantly share code, notes, and snippets.

@inodaf
Created June 28, 2019 12:20
Show Gist options
  • Save inodaf/16a620c83ea6c897fa93988d1d9520a8 to your computer and use it in GitHub Desktop.
Save inodaf/16a620c83ea6c897fa93988d1d9520a8 to your computer and use it in GitHub Desktop.
Find Intersection in Array
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