Can this code be edited to work on multiple arrays?

Can this code be edited to work on multiple arrays?
0

#1

Doing the advanced challenges and are currently stuck on the symmetric difference challenge. I wrote the code below, that works for the first test, however, I it doesn’t work when there are multiple arrays. Is there anything I can do?

function sym(args) {
	var single = [];
	var temp = Array.from(arguments).reduce(function(a, b) { 
  return a.concat(b);
}, []);
console.log(temp);

var res = temp.filter(function(v) {
  // get the count of the current element in array
  // and filter based on the count
  return temp.filter(function(v1) {
    // compare with current element
    return v1 == v;
    // check length
  }).length == 1;
});
return res;
}
sym([1, 2, 3], [5, 2, 1, 4]);

#2

How about, instead of combining the arrays in one large array, you compute for the symmetric differences of each array, piecemeal? I think symmetric difference can only take exactly two inputs. So you’ll first take the symmetric difference of the first two arrays, then the symmetric difference of that result and the third array, and so on.

Try to walk this through on paper with this test case:

sym([1, 2, 5], [2, 3, 5], [3, 4, 5]) should return [1, 4, 5]

It wouldn’t make sense for a 5 to appear in the output if symmetric difference can take all three arrays at the same time.