Diff Two Arrays - Help

I’m not sure why this won’t work.

Your code so far

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

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36.

Link to the challenge:

Your logic is a bit off in the above if statement. You already know that all the elements that were in arr1 and arr2 are going to be in arr, because you used concat to create arr with these elements. When you write:


this is always going to find an index of 0 or greater, so nothing will ever get pushed into newArr.

As the men above said: Concat is superfluous. You need two loops. One to compare using indexOf, first array elements to another, other loop to compare second array elements to first array. Inside ifs just chuck it into array that need to be returned.