Skip to content

Instantly share code, notes, and snippets.

@artemjackson
Last active February 3, 2017 20:38
Show Gist options
  • Save artemjackson/936e0bbd494ee1125085d1fb188a1876 to your computer and use it in GitHub Desktop.
Save artemjackson/936e0bbd494ee1125085d1fb188a1876 to your computer and use it in GitHub Desktop.
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