Tell us what’s happening:
Your code so far
function diffArray(arr1, arr2) {
var newArr = [];
for (var i=0; i<arr1.length; i++){
if (arr1.indexOf(arr2[i])===-1){
newArr.push(arr2[i]);
}
}
for (var j=0; j<arr2.length; j++){
if (arr2.indexOf(arr1[j])===-1){
newArr.push(arr1[j]);
}
}
// Same, same; but different.
console.log(newArr);
}
diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Why is it returning [4, undefined] ? wheres my mistake?
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays