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]);