Looking for feedback on the first working solution that I came up with for this challenge, it was hard to stay away from loops, trying to use JS methods so I can learn them better.
function sym(args) {
args = [].slice.call(arguments);
var symDif = args.reduce(function (first, second) {
return difTwo(first, second);
});
return symDif;
}
// Remove duplicate values from each array
function cleanUp(arr) {
return arr.filter(function (item, index) {
if(index === 0) {
return item;
} else if (arr.indexOf(item) == index) {
return item;
}
});
}
// Return a array with unique items
function difTwo(arr1, arr2) {
var array = cleanUp(arr1).concat(cleanUp(arr2));
var uniques = array.filter(function (item) {
let uniqueOne = arr1.indexOf(item) == -1 && arr2.indexOf(item) > -1 ? true : false;
let uniqueTwo = arr1.indexOf(item) > -1 && arr2.indexOf(item) == -1 ? true : false;
if (uniqueOne || uniqueTwo) {
return item;
}
});
return uniques;
}