I just completed the Mini Linter project. For step #4, I couldn’t figure out how to get what I wanted and had to watch the walkthrough video. Unfortunately, the walkthrough video does not complete the step using the iterator methods we learned, which seems the whole point of this exercise.
Here’s how I completed Step 4 after watching the video:
for (word of betterWords) {
if (word === 'really') {
reallyCount += 1;
} else if (word === 'very') {
veryCount += 1;
} else if (word === 'basically') {
basicallyCount += 1;
}
}
It seems like if we were creating a real linter, we would automate it by looping over every word in the overusedWords array and compare those words to the betterWords array, rather than declaring each word in a for-loop like the example video shows.
The problem is, I can’t figure out a how to get the methods to do what I want. So far, I can get an array that includes all the instances of overused words in the text:
const overusedCount = betterWords.filter(word => {
for (i= 0; i < overusedWords.length; i++) {
if (overusedWords[i] === word) {
return true;
}
}
}
)
console.log(overusedCount); // returns [ 'really',
'basically',
'really',
'very',
'very',
'very',
'very',
'very' ]
But I can’t figure out how to count all those words in a way that’s automated – i.e., in a way that doesn’t require me to look at each word and write a separate console.log statement for it. I want to generate the list of overused words automatically based on which words are in the list. Any ideas how I might do that?