How to remove every other repeated word

forEach doesn’t return anything
index has value of undefined

anyway, forEach is a method, it is being called where you wrote it, with a function as argument

like push for example, you write arr.push(1) and it adds the 1 to the array
when you use the round parenthesis after a function or method, you are calling it and it is being executed there

now, returning to index
delete it, forEach is a fancy way to write a loop, it doesn’t return anything
you should just write array.forEach(...) in a line on its own

1 Like

Ok so i would leave it like this then?

let overusedWordsCount = {};

overusedWords.forEach(overusedWord => {
  overusedWordsCount[overusedWord] = 0;
});

//console.log(overusedWordsCount);

const arrayWithRemovedWords = betterWords.filter(word => {
  if(!overusedWords.includes(word)) {
    return true;
  } else {
    overusedWordsCount[word]++;
    if(overusedWordsCount[word] % 2 != 0) {
      return true;
    } else {
      return false;
    }
  }
});

exactly like that , that’s correct

That’s amazing! I love learning new stuff and when i get the logic on something completely new…
TBH is awesome!

Thank for your help and tutoring on all my posts!! You are a star!!