Tell us what’s happening:
So I believe I am on the right track. and I am getting “pink wool” which is the element in arr1 that is not in arr2. However, I do not fully understand line 4 (line with the let). Can someone help me understand how the logic works? Particularly I do not understand “!arr2.includes(element)” cause I thought .includes returns a true or false? Also I thought filter returns everything that meets the criteria in the parentheses? Can someone help me understand the logic in line 4 step by step please?
Your code so far
function diffArray(arr1, arr2) {
// all the elements in arr1 that are not in arr2
let arr1Filter = arr1.filter(element => !arr2.includes(element));
console.log(arr1Filter);
}
diffArray(["andesite", "grass", "dirt", "pink wool", "dead shrub"],["diorite", "andesite", "grass", "dirt", "dead shrub"]);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Challenge Information:
Intermediate Algorithm Scripting - Diff Two Arrays