Unsure if I'm off logic-wise with this one

I feel like my logic makes sense; however, I’m returning an empty array and I’m not sure why.
Two different arrays. Filter out each array for what’s not in the other array (the different element) and set those remaining elements equal to a new array.

That’s what I’m doing right?

Thanks again,
Nick
Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

function diffArray(arr1, arr2) {
//newArr equals...
//arr1 filtered for only elements not in arr2
//concatenate filtered elements of arr2 not in arr1
//return newArr
const newArr = arr1.filter(x=>arr1.includes(!arr2)).concat(arr2.filter(x=>arr2.includes(!arr1)));
console.log(newArr)
return newArr;
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
  **Your browser information:**

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

Challenge: Diff Two Arrays

Link to the challenge:

I don’t think this does what you think this does

function diffArray(arr1, arr2) {
  // newArr equals...
  // arr1 filtered for only elements not in arr2
  // concatenate filtered elements of arr2 not in arr1
  // return newArr
  console.log(!arr2)
  const newArr = arr1
    .filter(x => arr1.includes(!arr2))
    .concat(arr2.filter(x => arr2.includes(!arr1)));
  console.log(newArr)
  return newArr;
}

Also, I think you have your conditions for the filters backwards wrt arr1 and arr2.

Should my algorithm be checking the typeof…because there is an includes() for strings and arrays and I’m getting feedback from the console indicating that what I’m typing is not a function which is usually an indication that I’m using a method on a data type for which it was not intended.
Nick

What is !arr2?

What does this line actually do?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.