Created
March 2, 2025 03:22
-
-
Save minhphong306/52f46d137a3c456a316c5afb65a5b7f6 to your computer and use it in GitHub Desktop.
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 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