This is for the Difference of Two Arrays challenge at freecodecamp
there’s something about the sintax to .indexOf that I’m not getting right… either, I’m filtering the wrong element or by the wrong element. I either get an empty array or an array with nothing filtered out…
function diffArray(arr1, arr2) {
//create an empty array
var newArr = [];
// Same, same; but different.
var r3 = arr1.concat(arr2);
console.log(newArr);
newArr = r3.filter(function(element) {
//return args.indexOf(element) === -1;
//filters the initial arr of any args that are contained in it
if (r3.indexOf(element) === -1) {
newArr.push(r3[element]);
} //end of if
}); //end of .filter, an anounoumous function
console.log(r3);
return newArr;
//return newArr;
}