I need to find the number of items in two arrays which are not duplicate.
Eg here the answer is 1:
const array1 = ['a', 'b', 'c', 'c']
const array2 = ['a', 'b', 'c']
Eg here the answer is 2:
const array1 = ['a', 'b']
const array2 = ['a', 'x', 'y']
My solution works for some inputs but not all:
function something(a, b) {
let aArray = a.split("");
console.log(aArray);
let bArray = b.split("");
console.log(bArray);
aArray.forEach((aItem, aIndex)=> {
console.log(aItem)
bArray.forEach((bItem, bIndex)=> {
console.log(bItem);
if(aItem === bItem) {
console.log(aIndex, bIndex);
aArray[aIndex] = "-";
bArray[bIndex] = "-";
}
});
});
console.log(aArray);
console.log(bArray);
const aRes = aArray.filter(item=> item !== "-").length;
console.log(aRes)
const bRes = bArray.filter(item=> item !== "-").length;
console.log(bRes)
const res = aRes + bRes;
console.log(res)
return res;
}