Mini Linter step 8.1 - logic

Hi! I am currently at mini linter project and almost finished. I tried the last step (8.1) and my code kinda works, but i am feeling like it’s not the best possible solution. Can someone please help me with right logic on this one?

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' ];

const storyWords = story.split(' ');
console.log('Story length is ' + storyWords.length);

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

const countOverused = storyWords.filter( word => overusedWords.includes(word) );
console.log('Number of overused words is ' + countOverused.length);

const countSentences = storyWords.filter( word => word[word.length-1]  === '.' || word[word.length-1]  === '!');
console.log('Number of sentences is ' + countSentences.length);

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

// 8.1

let a, b, c;
a = b = c = 0;
for (let i = 0; i < betterWords.length; i++) {
  if( betterWords[i] === 'really' ) {
    if ( a % 2 === 0 ){
      a++;
    } 
    else if (a % 2 !== 0) {
      betterWords[i] = '';
      a++;
    }
  } else if ( betterWords[i] === 'very' ) {
    if ( b % 2 === 0 ){
      b++;
    } 
    else {
      betterWords[i] = '';
      b++;
    }
  } else if ( betterWords[i] === 'basically' ) {
    if ( c % 2 === 0 ){
      c++;
    } 
    else {
      betterWords[i] = '';
      c++;
    }
  } else {
    continue;
  }
}

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

Hi,
can you link to the lesson, please? What does step 8.1 asks you to do?

sure https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-ii/modules/fecp-learn-javascript-syntax-iterators/projects/mini-linter

So the instructions want you to remove every other occurance of overused words. For another task you already wrote this function:

You could use it again and extend it with another condition including the modulo operator and include a counter for the occurances. I understand the instructions that way that you don’t have to distinguish the words in overusedWords.

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