I’m trying to solve this problem by
- creating a function that checks if a given number exists in and array
- 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: