Build a Symmetric Difference Function - Build a Symmetric Difference Function

Tell us what’s happening:

Your tests lacks some rules.For example:
My code:
function diffArray(arr1,arr2){
let arr=arr1.filter(b=>!arr2.includes(b))
return arr
}
passes the test while it is only checking symmetricity in first array not both.

Your code so far

function diffArray(arr1,arr2){
    let arr=arr1.filter(b=>!arr2.includes(b))
    return arr
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36

Challenge Information:

Build a Symmetric Difference Function - Build a Symmetric Difference Function
https://www.freecodecamp.org/learn/full-stack-developer/lab-symmetric-difference/lab-symmetric-difference

Welcome to the forum @amralsabbagh

Your function work for the first part of the requirements.

The filter method is checking that items from arr1 are not also in arr2.

The new array, named arr is the result of filtering out similar elements from both arrays.

Your code still needs to preform the same check for arr2.

Happy coding

if there is an item is only in the second array it will not be included in the returned array

Yes. You are correct that this is not the behavior for the symmetric difference. There was an open GitHub issue on this, which was closed just 2 days ago. It looks like the changes haven’t yet been pushed to prod though.

You’re on the right track, here i see you’ve filtered only elements in array1 & not in array2, so suggest you apply the concat method & filter for array2 hope this helps!

Please do not respond to old threads that are already answered

1 Like