Mini Linter Step 4 - Is there a universal string counter method?

Hi Coding Masters! :smiley:

As I was doing the Mini Linter exercise - I wonder if there is a way to automate the function… so that I don’t have to list if conditions one by one?

For example, if the “overusedWords” includes not just 3 strings but 100 strings to check the frequency in the storyWords - can you guide me if there is a way to do so?

I thought for so long but really couldn’t come up with an idea… LOL! :sweat_smile:

(code for this mini linter exercise step 4. Below code listed 3 if conditions one by one. )

let reallyCnt = 0;
let veryCnt = 0;
let basicallyCnt = 0;

for (word of betterWords) {
if (word === overusedWords[0]) {
else if (word === overusedWords[1]) {
veryCnt += 1;
else if (word === overusedWords[2]) {
basicallyCnt += 1;

console.log(reallyCnt, veryCnt, basicallyCnt) // output 2 5 1

Thank you! You are the best :heart_eyes:

There is a hint in there… It is one of the iterator class.