Mini linter step 8

Congratulations! You’ve improved the original paragraph and given the user some important information about his or her work. Think about ways in which you can extend this project, potentially by using other JavaScript knowledge you have.

Here are some ideas:

  1. For the overused words, remove it every other time it appears.

How do you do this step? (I’ve been working on this project for a week, just in case you wana tell me to go
google it) =)

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

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

const storyWords = story.split(' ');

console.log('words:', storyWords.length);

const betterWords = storyWords.filter(word => !unnecessaryWords.includes(word));

console.log('better words:', betterWords.length);

let reallyCount = 0;

let veryCount = 0;

let basicallyCount = 0;

for(word of betterWords){

  if(word === 'really'){

    reallyCount++;

  }else if(word === 'very'){

    veryCount++;

  }else if(word === 'basically'){

    basicallyCount++;

  }

};

console.log('overused words:', reallyCount + veryCount + basicallyCount);

console.log(' really count:', reallyCount);  

console.log(' very count:', veryCount);

console.log(' basically count:', basicallyCount);

let sentences = 0;

for(word of betterWords){

  if(word[word.length - 1] === '.' || word[word.length -1] === '!'){

    sentences++;

  }

};

console.log('sentences:', sentences);

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

const evenBetterWords = betterWords.filter(word => !overusedWords.includes(word));

console.log('even better words:', evenBetterWords.length);

https://www.codecademy.com/courses/introduction-to-javascript/projects/mini-linterPreformatted text

You used a for … of loop. For this task you could try a for loop with index (for let i = 0; i < arr.length; i++) and for each occurrence of the word in question, update a counter. If the counter is even, remove the word.

I’m sry I was and am very frustrated. I did respond yesterday. Today I deleted my responses because I was trying to delete that entire post, in hopes of reposting and getting another response. Now I’m trying to remember exactly what I don’t understand so I can ask you again. lol

Okay, I have an array called betterWords. I want to: const evenBetterWords = betterWords.filter(word => {})
Inside filter I need a callback function that returns every other word of overusedWords. I can’t figure that out. You told me to use a for loop. I tried that and I’m stuck.

If you filter the original array ‘betterWords’ and use a callback that let’s just every 2nd word of overusedWords pass, then your result will be the content of overusedWords only. That’s not what you want, right?

I am sure that the task will be easier if you use a for loop that also takes the index into account. So no for … of loop (see my post above).

Then you could have a variable named counter initialized as 0 if you do not want to make a distinction of the words stored in overusedWords. For the start, that would be easier.

As an example: You have two words in overused words – literally and extremely.
Your betterWords are

‘Literally, I was extremely shocked by literally everything’.

If you have one counter for all overused words and filter out every other, the result would be:

‘Literally, I was shocked by literally everything’

Maybe not what the task asks for, but good for a start. You could refactor later.

Then you loop through your betterWords array and if the word can be found in the overusedWords array, you set the counter variable up by one.
You can push all words from the betterWords array to a new array called evenBetterWords. But if the word from betterWords can also be found in overusedWords AND the value of the counter variable is odd, you do not push the word to the new array.

reallyCount = 0;
veryCount = 0;
basicallyCount = 0;

const evenBetterWords = betterWords.filter(word => {
  for(let i = 0; i < overusedWords.length; i++){
    if(overusedWords[i] === word){
      reallyCount++;     
      veryCount++;
      basicallyCount++; 
      if(reallyCount % 2 === 0){
        return 'really';
      }if(veryCount % 2 === 0){
        return 'very';
      }if(basicallyCount % 2 === 0){
        return 'basically';
      }
    }
  }
});

The output for this is:
even better words: [ 'basically', 'very', 'very', 'very' ]
I'm trying to get every other word. Plus I need to include all the other words in betterWords. What am I doing wrong?
  1. You are using a for loop in a filter method. That’s not a good practice.
  2. You are returning from a for loop. That’s not how a for loop is used.
  3. You are returning strings. The filter method expects true or false as return values from the callback function.
  4. You update three counters at once for every occurrence, which makes having a distinction of the words rather useless.
  5. You are welcome btw

I recommend that as a first attempt you try it the way that I suggested. That is the easiest I can think of.

Blockquote

That’s the problem. I don’t understand how to write code out of your suggestion. I gota take a break for a couple hours. I’ll come back and look over your suggestion word for word and try to make sense of it