# Mini linter extra challenges

I have just finished the mini linter project challenge and came up with my own solutions for 2/3 of the extra challenges.

1. For the overused words, remove it every other time it appears.
2. Write a function that finds the word that appears the greatest number of times.
3. Replaced overused words with something else.

I figured out a way to solve challenge 1 and 3 using a for loop, some if statements, and the `.splice()` method

I didn’t put too much time into thinking about challenge 2 because I plan to move on with the course. But I do find that one a bit harder to solve. I’m sharing my code here incase anyone else is curious to see my solutions, and perhaps someone might have some ideas about challenge 2 that they may want to share.

https://gist.github.com/31366bf3de3f418e0364afd07840226b

PS. I didn’t follow challenge 3 to the letter but I liked the idea of replacing every other overused word with a new one, but I could have done a quick copy and paste of my code for `reduceOverused()` and modified a few of the if statements slightly to follow challenge 3 more exactly.

1 Like

I find it helpful to tackle some problems in a different way than they’re worded.

Write a function that finds the word that appears the greatest number of times. That sounds like a lot to approach at once.

I broke the challenge down into 2 problems:

1. Count how many times each word appears.
2. Find the word that has the highest count.

Nice code

1 Like

I though of those two steps but off the top of my head I couldn’t work out a method to count how many times each word appears without manually creating a variable for each word

Instead of tracking the count of each word, maybe a ‘high score’ would be easier to track? Only keep track of the word that has shown up the most and replace it if one beats the score. Here’s a rough sketch:

``````let highscore
let mostUsedWord
// Use a loop to get each word from the story
For each word in the story
let count
// Then loop again
for each word in the story
if the words match
count++
if count > highscore
highscore = count
mostUsedWord = word
``````

We are essentially tallying each word - but if it doesn’t beat the score we don’t care to keep.

There is a way we could track each word by pushing an object representing a word and a count into an array, but I believe the object lessons are ahead of this project.

3 Likes

Hi,
Any one can say why this code is not doing what is asked at step1 of 8th question?
Thanks