Tell us what’s happening:
My output looks correct but it still tells me that it’s not. Any ideas?
Your code so far
function checkArray(arr1, arr2, newArr) {
for (let i = 0;i < arr1.length; i++) {
for (let j = 0; j < arr2.length; j++) {
if (arr1[i] == arr2[j]) { // if equal
break; // we disregard that element in arr1 and move to the next.
} else if (j === arr2.length -1) {
newArr.push(arr1[i]);
}
}//end of inner for loop
}//end of outer for loop
}//end of function
function diffArray(arr1, arr2) {
var newArr = [];
// Same, same; but different.
if (arr2 == undefined) {
return arr1;
}
checkArray(arr1, arr2, newArr);
checkArray(arr2, arr1, newArr);
return newArr;
}
console.log(diffArray( ["snuffleupagus", "cookie monster", "elmo"]));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
.
Challenge: Diff Two Arrays
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays