Mini Linter Step 8

RE: https://www.codecademy.com/courses/introduction-to-javascript/projects/mini-linter

I’m trying to do the “extra credit” in step 8, but am blanking out and am not sure where to get started.

For #1:

I found someone else on here that used something like this:

var modOverusedWordsCount = 0;
var modBetterWords = betterWords.filter(word => {
  if (overusedWords.includes(word)) {
    modOverusedWordsCount++;
    if (modOverusedWordsCount % 2 !== 1 || modOverusedWordsCount % 2 === 1) {} else {
    return word;
  }
}});

Can someone check my understanding here? Basically, I’m reading this as the function will take words in the betterWords array and, if they’re included in the overusedWords array, it’ll bump the counter variable up. I’m a little hazy in terms of what the index (%2) is doing…

If I log modBetterWords to the console, I get an empty array.

///

For #2 and #3, does anyone have any hints as to where to get started? My mind goes to doing something similar to the above with different logic?

modBetterWords isn’t a function, it’s the result of calling betterwords’ filter method
The filter method accepts a function as one of its arguments. You may get a better view of what is going on if you create that function separately instead of as an anonymous function.

For #2 you might want to count how many times each word appears (you’d need to keep multiple counts, one for each word. use the word itself as the key for finding the right count)

I wrote a function that will take two arrays, one you’re trying to filter out the overused words from every other overused word.

Blockquote
const removeEveryOther = (array1, overusedArray) => {
let counter = 1;
for (let i = 0; i < array1.length; i++) {
for (let j = 0; j < overusedArray.length; j++) {
if (array1[i] === overusedArray[j] && counter < 2) {
counter += 1;
}
else if (array1[i] === overusedArray[j] && counter >= 2) {
array1.splice(i, 1, ‘’);
counter -= 1;
}
else {
;
}
}
}
const evenBetterWords = array1.filter(word => {
return word.length > 0;
});
console.log(evenBetterWords.join(’ '));
};

// removeEveryOther(betterWords, overusedWords); outputs the desired text.