Mini Linter Project (Extra tasks)

Hello everyone,
Finally I’ve done writing a code for the project about the iterators, called : Mini Linter. This is the link for the project : Mini Linter Project

The task was is to remove the overused words every other time it appears. Or even replace them with something else (if I can delete them, I can replace them)

This is the code I’ve written :

let story = 'Last weekend, I took literally the most beautiful bike ride of my life. The route is called "The 9W to Nyack" and it actually stretches all the way from Riverside Park in Manhattan to South Nyack, New Jersey. It\'s really an adventure from beginning to end! It is a 48 mile loop and it basically took me an entire day. I stopped at Riverbank State Park to take some extremely artsy photos. It was a short stop, though, because I had a really long way left to go. After a quick photo op at the very popular Little Red Lighthouse, I began my trek across the George Washington Bridge into New Jersey.  The GW is actually very long - 4,760 feet! I was already very tired by the time I got to the other side.  An hour later, I reached Greenbrook Nature Sanctuary, an extremely beautiful park along the coast of the Hudson.  Something that was very surprising to me was that near the end of the route you actually cross back into New York! At this point, you are very close to the end.';

let overusedWords = ['really', 'very', 'basically'];

let unnecessaryWords = ['extremely', 'literally', 'actually' ];

let storyWords = story.split(' ');

// Remove all unecessary Words
let betterWords = storyWords.filter(word => !unnecessaryWords.includes(word));

// Variables to count overused words
let reallyCount = 0;
let veryCount = 0;
let basicallyCount = 0;

betterWords.forEach(word => {if (word === 'really') {
   } else if (word === 'basically') {
   } else if (word === 'very') {
console.log(`The word really is repeated ${reallyCount}, the word very is repeated ${veryCount}, the word basically is repeated ${basicallyCount}`);

// Variable to count sentences in the paragraphe
let countSentences = 0;
betterWords.forEach(word => {
  if (word[word.length-1] === '.' || word[word.length-1] === '!') {
    return countSentences++;

// wordIndex save the index of the overused word each time found in the text
let wordIndex = [];
function overusedWordsIndex (word) {
    for (let i=0;i<betterWords.length;i++) {  
    if (betterWords[i] === word) {
  return wordIndex.shift();
// I call the function for the word very 

// This function will remove the overused words
  function removeWords () {
  let j = wordIndex.length-1;
    while (j >= 0) {

console.log(betterWords.join(' '));

With this logic the problem is that I can’t get the indexes for all the word in the array (overusedWords), only one word. Even if I call the function for each word. I don’t know how I can loop and check the indexes for every word in the overusedWords array.
I want to create nested arrays where there are values (indexes) of each word, so I can remove them all in one time.

Sorry for my bad English, but I guess that the code could help to understand what I’m trying to do.

Rather than create an object to track the indices of the words you want to replace, which wouldn’t scale well for a longer list of words to be replaced, would it not be better to keep repeating the replacement action until there are no more instances of a given unwanted word?

Can you think of a loop that allows you to repeat an action without needing to know ahead of time how many iterations you need?