Last active
September 30, 2019 10:20
-
-
Save cenkce/5b7411bb6d01e04457eb1eee2fec9c9e to your computer and use it in GitHub Desktop.
Find uncommon values between two arrays
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 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