Mini Linter Task 8/1

Hi everyone!

I’m on the solving of Mini Linter. The whole task is very challenging, but from the last point, question number one gives me extra headache. I found on Github an interesting solution, but I don’t understand the logic. Can somebody explane it?

The question : For the overused words, remove it every other time it appears.

let overusedWC = {
  return 0;

///Initiate a count for removed words
let removedWC = 0;

///Filter out every other instance of the contents of 'overUsedWords'
let lessOverusedWords = {
  if (!overusedWords.includes(storyWord)) {
    return storyWord;
  } else {
    let pos = overusedWords.indexOf(storyWord);
    if (overusedWC[pos] < 1) {
      return storyWord;
    } else { ///Add alternative word
      overusedWC[pos] = 0;
      ///Here we could pull from an array of alternative words
      return 'REMOVED';

So, what I don’t really understand, it is,
1, why do we need to give a new value (0) for the overusedWords,
2, the pos variable, and
3, the if…else statement afterwards.

Thanks in advance!

You could print out what’s being done and look at the output.
If you consider things like when something is done and what would happen without it, you’d see the why of it.

So, observe.

Or approach it from the other end. Ask yourself what needs to happen, and then match that up to the code.

Also you seem to be making the assumption that it’s correct. You can’t really say that without knowing what it does.

You can also execute it manually. Do you know what each thing in the code does? If not, then you’ve got something you can look up. Or if you do, then carry those instructions out and observe what you end up doing.