Find the Symmetric Difference (Created seperate compare function))

Tell us what’s happening:
Describe your issue in detail here.

Hows it going, I am having some trouble implmenting this idea in my head that I know works… I made a compare function that did symmetric difference between 2 arrays but I am having some trouble doing it for multiple, though I do have an idea on paper which I will explain below.

the idea goes as follows:

example: “sym([1, 2, 5], [2, 3, 5], [3, 4, 5])”

i.) arr =
ii.) compare( , [1,2,5]) → [1,2,5]
iii.) compare([1,2,5] ,[2,3,5]) → [1,3]
iV.) compare ([1,3] ,[3,4,5]) → [1,4,5]

so basically I start with an empty array which I would use to compare with the first array to get [1,2,5], then using that same answer I would compare it to [2,3,5] to get [1,3] and finally [1,3] compares with [3,4,5] to get our answer [1,4,5]. I have implmented the compare function but cant implment the rest.

example input

  **Your code so far**

function sym(…args) {

let n = args.length;

let arr =;

for(let i = 0; i < n; i++){


arr = compare(args[0],args[1]);


return args;


function compare(arr1,arr2){

let x = arr1.filter(x => {return !arr2.includes(x)});

let y = arr2.filter(x => {return !arr1.includes(x)});

let z = x.concat(y).sort((a,b) => {return a-b});

return z;


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

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0

Challenge: Find the Symmetric Difference

Link to the challenge:

Please disregard I have solved it :smiley:

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