On the Intermediate Algorithm Scripting: Diff Two Arrays challenge, I am trying to solve it with a for loop (it’s the only way I can kind of do on my own right now). However, I’m getting stuck, and I’m not sure it’s even possible to do it this way, but I would like to see. my junkArr returns everything that is the SAME between the two arrays, and my intention is to have newArr contain everything else, and therefore the correct answer to the challenge. Is there something I can put into newArr.push() that would make that happen? Thanks
function diffArray(arr1, arr2) {
var newArr = [];
var junkArr = [];
for (var i=0; i<arr1.length; i++){
for(var j=0; j<arr2.length; j++){
if(arr1[i]===arr2[j]){
junkArr.push(arr1[i]);
} else {
newArr.push();
}
}
}
return newArr;
}
diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);