Type error in Function

I’m trying to solve this problem by

  1. creating a function that checks if a given number exists in and array
  2. using filter with this function on the next array to return just the elements that are different

I’m getting type errors in function though and I can’t figure out why:

TypeError: num is not a function

Can Anyone help? Thanks in advance!

  **Your code so far**

function diffArray(arr1, arr2) {
function inArray(num, items){
  let test = items.findIndex(num);
  return test === -1 ? false : true;
}

return arr1.filter(x => !inArray(x, arr2));
}

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

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:94.0) Gecko/20100101 Firefox/94.0

Challenge: Diff Two Arrays

Link to the challenge:

Because “num” is not a function :wink:
Why is that a problem? Well because .findIndex() is expecting a function as argument. The method you want it .indexOf().

1 Like

Thankyou! :sweat_smile:
I was going nuts. should have thought to reread the docs.

The findIndex() method returns the index of the first element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating that no element passed the test. 
1 Like