# Symmetric difference

I am struggling to get past the symmetric difference challenge. Here is my code:

``````function sym(...args) {
function symDiff(arr1, arr2) {
var arr1Diff = arr1.filter(x => !arr2.includes(x));
var arr2Diff = arr2.filter(x => !arr1.includes(x));
const arr = arr1Diff.concat(arr2Diff);
return Array.from(new Set(arr.sort()));
}
return console.log(args.reduce((a,b) => symDiff(a, b)));
}

sym([1, 2, 3], [5, 2, 1, 4]);
``````

I think the output matches the intended output, but I am unsure where the code is wrong.

1 Like

console.log has a return value of `undefined`

1 Like

can you post a link to it

Why this line

``````   return Array.from(new Set(arr.sort()));
``````

isnâ€™t just

``````return arr.sort();
``````

?

Thanks for your help! Storing the result in a variable and returning the variable solved the challenge.

If I donâ€™t use the sort method, a set is created with unsorted unique values.

I never removed the sort

``````return arr.sort();
``````

Correction: nope, it doesnt.

Is there any simple reason why `return arr;` isnâ€™t working in that step (return of first function)? (Without sorting and making it a set, as it should be a set anyways, I think).

I couldnâ€™t read the whole requirements but it sounds fine to me comparing to OP code.

There can not be a duplicate imho in the concatenation, in the way those arrays are filtered.

`[1,3,4]`, `[2,4]` will return `[1,3]` and then just `[2]` and then concatenate.

Also, the code that is logged in the console has all the arrays ordered (not saying this is requirement, but it looks like it.)

Sorry, I got it. The arrays arenâ€™t set from the beginning. That was a wrong assumption. Yes I read the same test from the console.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.