Skip to content

Instantly share code, notes, and snippets.

@decentraliser
Last active August 11, 2020 08:07
Show Gist options
  • Save decentraliser/e213369da5be3290bad83a786539547b to your computer and use it in GitHub Desktop.
Save decentraliser/e213369da5be3290bad83a786539547b to your computer and use it in GitHub Desktop.
Test for arrays intersections with array.some
// array some helps keeping code succinct when looking for occurences in arrays
const firstArray = ['shark', 'fish', 'dinosaur']
const secondArray = ['whale', 'shark', 'bird']
const thirdArray = ['raptor', 'tuna']
// determine wether 2 arrays have a similar entry
const bool1 = firstArray.some(animal => secondArray.some(otherAnimal => otherAnimal === animal))
console.log("bool1", bool1) // true, "shark" is in both arrays
const bool2 = firstArray.some(animal => thirdArray.some(otherAnimal => otherAnimal === animal))
console.log("bool2", bool2) // false, firstArray and thirdArray have no similar entry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment