Skip to content

Instantly share code, notes, and snippets.

@Woodsphreaker
Created August 6, 2017 22:16
Show Gist options
  • Save Woodsphreaker/f4b52973b7ea3a10c88dec894a973aec to your computer and use it in GitHub Desktop.
Save Woodsphreaker/f4b52973b7ea3a10c88dec894a973aec to your computer and use it in GitHub Desktop.
Compare Array
const arr1 = [1,2,3,4,5,6,7]
const arr2 = [1, 3, 5, 7]
const filter = (el) => !arr2.includes(el)
const filter2 = (el) => arr2.indexOf(el) === -1
const filter3 = (el) => arr2.every(el2 => el2 !== el)
const filter4 = (el) => !arr2.some(el2 => el2 === el)
console.log(arr1.filter(filter))
console.log(arr1.filter(filter2))
console.log(arr1.filter(filter3))
console.log(arr1.filter(filter4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment