Mini Linter Solution Suggestions

Hi there!

After reviewing the Mini Linter solution under Get Unstuck, I wasn’t too crazy about having to hard-code the individual overused words inside conditional statements. Besides, I certainly don’t want as many conditional statements as there are words in the overusedWords array.

Here’s a general solution that capitalizes on the various lessons and the recommended Mozilla documentation.

// Count total number of occurrences of overused words.
// Initialize count as an empty array.
let overusedWordCount = ;

storyWords.forEach(word => {
for (i = 0; i < overusedWords.length; i++) {
if (isNaN(overusedWordCount[i])) {
overusedWordCount.push(0);
}
if (word === overusedWords[i]) {
overusedWordCount[i]++;
}
}
})

// Display total number of occurrences of overused words.
overusedWords.forEach(word => {
const i = overusedWords.indexOf(word);
console.log(word + ': ’ + overusedWordCount[i]);
})

2 Likes

I know you posted this a few months ago, but thank you so much! I, too, was bothered by the multiple conditionals in the solution and KNEW that there must be a way to generalize it. I struggled for a few hours trying to come up with a better solution, but couldn’t get mine to work. Your solution helped me realize what, exactly, I wanted to do with my code and then I was able to fix my errors. Thank you again!

1 Like