Diff Two Arrays help

it not working at all and it should be right.

Your code so far


[spoiler]function diffArray(arr1, arr2) {
  var newArr = [];
  // Same, same; but different.
  for (var i = 0; i<arr1.length;i++) {
    if (arr2.indexOf(arr1[i]===-1)){
      newArr.push(arr1[i]);
    }
  } 
  for (var j=0;j<arr2.length;j++) {
    if(arr1.indexOf(arr2[j]===-1)){
      newArr.push(arr2[j]);
    }
  }
  return newArr;
  
}





diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);[/spoiler]

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0.

Link to the challenge:

Hmm… it’s not quite right. Close though!
Here’s the problem:

Inspect that code very carefully. Currently, it checks if the item is -1.

You need to add a console.log before your return statement. For the first test case you are returning the following array:

[ 1, 2, 3, 5, 1, 2, 3, 4, 5 ]
2 Likes

I got thanks for the help