Last active
February 3, 2017 20:38
-
-
Save artemjackson/936e0bbd494ee1125085d1fb188a1876 to your computer and use it in GitHub Desktop.
This file contains 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 arrayDiffIndexes = (smallestArray, biggestArray) => { | |
const common = {}; | |
smallestArray.forEach(item => { | |
common[item.key] = true; | |
}); | |
const diffIndexes = []; | |
biggestArray.forEach((item, index) => { | |
if (!common[item.key]) diffIndexes.push(index); | |
}); | |
return diffIndexes; | |
} | |
const array1 = [{ key: 1 }, { key: 2 }, { key: 3 }]; | |
const array2 = [{ key: 3 }, { key: 4 }, { key: 2 }, { key: 1 }]; | |
const diffIndexes = arrayDiffIndexes(array1, array2); | |
console.log(diffIndexes); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment