Mini linter step 4

Can someone help me with this? im stuck and a bit rusty

I know this is an older question, but just in case someone else comes along at a later date who will have this same question, I decided to share my approach.

const overusedWordsCount = betterWords.filter(words => {

return overusedWords.includes(words);

}).length;

Here is the breakdown:

  1. By using the .filter method, JavaScript will sift through the array and return a new array to me.
  2. This new array is based on the criteria: in this case, the number of times that the words in the overusedWords variable occurs.
  3. Once the program runs and the new array results, I then call apply .length method to it which will sum all the elements in this new array and give me a final figure.

I found this approach much shorter and straight forward than trying to write the if/else statements or whatever other approach could have been used.

If there are any professional programmers who will see this and find an issue with how I wrote the code, just drop a comment below and let me know how it can be improved.