JAVASCRIPT SYNTAX, PART II Mini Linter - How do i remove overused words from the array

Welcome to the Get Help category!

The words are found arent being removed from the betterwords are an array in the last filter function at the end of the page, logically my code makes but i don’t know what missing. can someone please explain its not working.

et 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(storyWords.length);

const betterWords = storyWords.filter(word =>{

  return !unnecessaryWords.some(unnecessaryWord =>{

    return unnecessaryWord === word;

  });

  

});

//console.log(betterWords);

let i = 0;

let j = 0;

let k = 0;

const amountOfWords = betterWords.forEach(word =>

{

  

  if(overusedWords[0] === word)

  {

    //let i = 0;

    //console.log(i);

    i = i + 1;

  }

  if(overusedWords[1] === word)

  {

    //let i = 0;

    //console.log(i);

    j = j + 1;

  }

  if (overusedWords[2] === word)

  {

    //let i = 0;

    //console.log(i);

    k = k + 1;

  }

});

let sentences = 0;

let amountOfSentences = betterWords.forEach(sentence => {

  if(sentence.endsWith('.') == true)

  {

    sentences += 1;

  }

  if(sentence.endsWith('!') == true)

  {

    sentences += 1;

  }

});

console.log(`The amount of times the word ${overusedWords[0]} has been used is: ${i}`);

console.log(`The amount of times the word ${overusedWords[1]} has been used is: ${j}`);

console.log(`The amount of times the word ${overusedWords[2]} has been used is: ${k}`);

console.log(`The amount of sentences is:  ${sentences} `);

console.log('The original story contains ' + storyWords.length + ' words\n');

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

const removedOverWords = storyWords.filter(word =>{

  return overusedWords[betterWords.indexOf(word)] !== word;

})

console.log(removedOverWords.join(' '));```
* (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)

1. List item

hi @mustafaal-obeid74498 ,

I’ve tested your code and realized the method you’re trying (i.e., .indexOf(value)…) is rather complicated because the moment when the following…

Produces index more than overusedWords array length, all your values return is undefined but at some point it’d return false because the returning character or word’s index is within the array length.

1 Like