Instead of using an anonymous function, how can I convert the statement arr2.includes(element) into a named function that can be passed in?
const ArrayOverlap = (arr1, arr2) => {
let newArr = [];
return newArr = arr1.filter(element => arr2.includes(element));
}
If I were to attempt something like this:
const ArrayOverlap = (arr1, arr2) => {
let newArr = [];
return newArr = arr1.filter(bothIncluded(arr1, arr2));
}
function bothIncluded(arr1, arr2) {
for(const item of arr1){
return arr2.includes(item);
}
}