I've been having some trouble figuring out how to find the differences between 2 multi dimensional arrays.
These are the arrays:
let arr1 = [["Tag2","TES"],["Tag3","TES"],["Fedex Ground","TES"],["Fedex Air","TES"],["AMER","TES"],["CA BC","TES"],["EMEA","TES"],["Express","TES"],["tag-5","TES"]]
let arr2 = [["Tag2","TES"],["Tag3","TES"],["Fedex Ground","TES"],["Fedex Air","TES"],["AMER","TES"],["CA BC","TES"],["EMEA","TES"],["testingTag","TES"],["Express","TES"],["tag-5","TES"], ["tag-6", "TES"]]
And I would like the result to be a 2 dimensional array of the tags that do not exist in both arrays, so in this case:
resultArr = [["testingTag","TES"],["tag-6","TES"]]
I have been able to successfully retrieve all the tags that match in the array.
With this, I then tried looping through the arr2 with all the matching tags and pushing to an array if the tag in the loop did not match the tag in the arr2[i], and before pushing to array I would check if the tag already existed in the array I was pushing too, if it did then I would remove it from the array. But the logic I have explained here did not work out and all it did was confuse me more.
Code to the logic I just tried explaining:
let existingTags = [], deletedTags = [];
//Checks which tags are not to be deleted
for(let i=0; i<newTags.length;i++){
for(let j=0; j<oldTags.length;j++){
if(newTags[i][0] == oldTags[j][0]){
existingTags.push(newTags[i][0])
}
}
}
//Pushes to array the tags to be deleted
for(let i=0; i<existingTags.length;i++){
for(let j=0; j<oldTags.length;j++){
if(existingTags[i] != oldTags[j][0]){
deletedTags.push(oldTags[j][0])
}else{
for(let k=0; k<deletedTags.length; k++){
if(oldTags[j][0] == deletedTags[k]){
deletedTags.splice(i,1)
}
}
}
}
}
Would there be a simpler and more efficient way of finding the differences between 2 multidimensional arrays?