Tell us what’s happening:
I’ve been trying to solve this problem for a long time and when I thought I made it I got one thing wrong and I don’t really know how to correct it. I’m worried that my whole code might be incorrect and I’m doing it wrong, so if you have a chance please have a look at it and help me to see the right path.
Thanks in advance.
Your code so far
function diffArray(arr1, arr2) {
var newArr = [];
var temp;
var temp5;
for (var i = 0; i<arr1.length; i++){
temp = arr1[i];
if(arr2.indexOf(temp) === -1){
newArr.push(temp);
}
for (var j = 0; j<arr2.length; j++){
temp5 = arr2[j];
if(arr1.indexOf(temp5) === -1){
newArr.push(temp5);
}
}
}
// Same, same; but different.
return newArr;
}
diffArray([], ["snuffleupagus", "cookie monster", "elmo"]);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/diff-two-arrays