const betterWords = storyWords.filter(function(x){
return !unnecessaryWords.includes(x)}) // THE FINAL WORD COUNT IS 182.
const betterWords = storyWords.filter(function(x){
if (x != unnecessaryWords[0] && x != unnecessaryWords[1] && x != unnecessaryWords[2])
return x}) // THE FINAL WORD COUNT IS 179.
Could anybody tell me why the word count is different when both of these filter functions should do exactly the same job? Many thanks
This is either true or false – a bolean. That is what the filter method expects as a return value from the callback function.
This returns the value stored in the filtered array. That is not what the filter function expects. I don’t know why the filter has 3 items less, but the first example is the better solution and probably stores the correct result.
Thank you for the response, I put both of the different paragraphs into a WordCounter online and they both have returned 178 words. I do not understand