Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save minhphong306/52f46d137a3c456a316c5afb65a5b7f6 to your computer and use it in GitHub Desktop.
Save minhphong306/52f46d137a3c456a316c5afb65a5b7f6 to your computer and use it in GitHub Desktop.
const listA = [1, 2, 3, 4];
const listB = [4, 5, 6];
// Build map
const mapA = {
'1': true,
'2': true,
'3': true
};
listA.forEach(item => mapA[item] = true);
const mapB = {};
listB.forEach(item => mapB[item] = true);
const onlyA = [];
const onlyB = [];
// cal
listA.forEach(item => {
if (!mapB[item]) {
onlyB.push(item);
}
})
listB.forEach(item => {
if (!mapA[item]) {
onlyA.push(item);
}
});
console.log(onlyA);
console.log(onlyB);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment