Mini linter - removing every other overused word

Hi guys,

I have been very stuck on the above task, which is to remove every other word (contained in the array ‘overusedWords’) from the main passage ‘betterWords’, a long array of words making up a story.

let overusedWords = [‘really’, ‘very’, ‘basically’];

Focusing just on the word ‘really’, here is what I have come up with, with no success so far.

for (let word of betterWords) {
if (word === ‘really’ && word % 2 !== 0) {
betterWords.splice(word, 1)
}
}

Any advice welcome, thank you

word % 2 !== 0

I would reconsider this line and what you want it to do.
Remember the for-loop is going to iterate (cycle) through all the words of a list. What does it mean to say "really" % 2 !==0?

I get what you are saying here, but the issue i’m having is, how do I represent the index number of the word in this piece of code? I have no ‘i’ here

There’s a couple of things you can consider doing. You can use the size of the list as boundary markers if you want to use indexes.

I have modified it to the following, which managed to remove all the overused words:

for (let word of betterWords) {
// if statement inside that
// using includes, checking if overUsed contains any of the same word
if (overusedWords.includes(word)) {
// index of function returns first value at given index
let removedIndex = betterWords.indexOf(word);
if (removedIndex > -1) {
betterWords.splice(removedIndex, 1);
}
}
}

but still having no success in removing every other word when using this code:

for (let word of betterWords) {
// if statement inside that
// using includes, checking if overUsed contains any of the same word
if (overusedWords.includes(word)) {
// index of function returns first value at given index
let removedIndex = betterWords.indexOf(word);
if (removedIndex > -1 && removedIndex % 2 === 0) {
betterWords.splice(removedIndex, 1);
}
}
}

What is the result? One issue with iteration and removal is that the list changes and so the indexes can sometimes shift…

The question you should consider is how to remove a set known indexes from a list. I’ll leave it open in case you want to solve it yourself, otherwise it’s a quick google search away…

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.