Created
August 6, 2017 22:16
-
-
Save Woodsphreaker/f4b52973b7ea3a10c88dec894a973aec to your computer and use it in GitHub Desktop.
Compare 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 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