Tell us what’s happening:
I have a doubt with the commented part
I’m unable to figure out the use of it
I want a detailed explanation of how it is working…
Your code so far
function diffArray(arr1, arr2) {
const result = [];
const items = new Set([...arr1, ...arr2]);
items.forEach(item=> {
if(!arr1.includes(item) || !arr2.includes(item)){ //Here, what is necessity of ! operator?
result.push(item);
}})
return result;
}
console.log(diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Diff Two Arrays
Link to the challenge: