Skip to content

Instantly share code, notes, and snippets.

@cenkce
Last active September 30, 2019 10:20
Show Gist options
  • Save cenkce/5b7411bb6d01e04457eb1eee2fec9c9e to your computer and use it in GitHub Desktop.
Save cenkce/5b7411bb6d01e04457eb1eee2fec9c9e to your computer and use it in GitHub Desktop.
Find uncommon values between two arrays
const firstArray = ['a', 'b', 'c', 'd', 'e'];
const secondArray = ['a', 'b', 'c', 'x', 'a', 'k', 'x','a','r'];
const acc = {};
const table = {};
function explore(val){
if(val !== undefined && !acc[val]){
table[val] = true;
} else if(val !== undefined) {
delete table[val];
}
if(val !== undefined)
acc[val] = true;
}
(firstArray.length > secondArray.length
? firstArray
: secondArray
).forEach((_, index) => {
const first = firstArray[index];
const second = secondArray[index];
if(first !== second){
explore(first);
explore(second);
}
});
console.log(table);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment