Mini Linter step 4 overused words - is this also right?

So I initially read the question as “count the number of times ‘overusedwords’ were used” and I wrote this:

let countOverusedWords = storyWords.filter(x => overusedWords.includes(x)).length;

which equals 8. I know it doesn’t tell you how many times each ‘overusedword’ was used, but to count the total, would this be a good way to write it? Thanks.

If it works, it works :wink:

You could split this up and get a little bit more out of this by first storing the overused words in an array. And as a next step find out the amount of overused words by applying the length. Like so:

let overusedWordsInStory = storyWords.filter(x => overusedWords.includes(x)); // gives you an array of each overused word in the story, you can do anything with this now

let countOverusedWords = overusedWordsInStory.length; // count the amount of overused words
1 Like