Mini linter project

let betterWords = storyWords.filter(function(word) {
return !unnecessaryWords.includes(word);
})

What does this line of code mean? I’m having trouble making sense of it.
The filter() method is going through each element in the storyWords array. For each word it checks…// this is where I’m drawing a blank

The callback function of the filter iterator is, in this example, checking that each word in betterWords is NOT in unnecessaryWords. If that is the case, the word is allowed into the return array.

‘Includes’ denotes membership. Having found the word we don’t want, we NOT that boolean (Array.includes() returns a boolean) so it toggles to false. ! is the NOT logical operator in JavaScript, and many other languages, as well.

1 Like