Mini Linter Project step 8 - 3

Hello, :grinning:
I’m done with the Mini Linter Project just a few minutes ago.
I solved the third task which of step 8.
(Replaced overused words with something else.)
I wanna share my code and discuss with you guys whether it is okay or not.

Here is the link to the project.
Mini Linter

And, here is my code!

while(storyWords.indexOf('really') != -1) {

  storyWords.splice(storyWords.indexOf('really'), 1, 'OMG');

}

while(storyWords.indexOf('very') != -1) {

  storyWords.splice(storyWords.indexOf('very'), 1, 'OMG2');

}

while(storyWords.indexOf('basically') != -1) {

  storyWords.splice(storyWords.indexOf('basically'), 1, 'OMG3');

}

console.log(storyWords.join(' '));

//The result is
//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 OMG an adventure from beginning to end! It is a 48 mile loop and it OMG3 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 OMG long way left to go. After a quick photo op at the OMG2 popular Little Red Lighthouse, I began my trek across the George Washington Bridge into New Jersey.  The GW is actually OMG2 long - 4,760 feet! I was already OMG2 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 OMG2 surprising to me was that near the end of the route you actually cross back into New York! At this point, you are OMG2 close to the end.

Welcome any idea or opinion of yours.

Thank you. :blush:

3 Likes

Hello, and welcome back to the forums

Good job coming up with a solution for one of the bonus features of the project! Your solution definitely meets the requirements and you were able to put the array methods you learned in the lesson to good use.

As with almost everything in programming, there are a lot of ways to accomplish that particular tasks. You’ll come across other strategies as you continue the lessons.

1 Like

Hey your code is awesome :star_struck: I also found a cool way to get the frequency of each string in an array!

const overusedWordArray= storyWords.filter(word =>{

return overusedWords.includes(word)

})

console.log(overusedWordArray)

// Create a function that takes an array as a parameter

const getFrequency = (array) => {

// create an empty object

let overusedWordCount= [emptyarray];

// for each word in the array

array.forEach(word => {

//check if there is an overused word already in the object, if not it will create a key and the value will start at 1. As it goes through each word it will add 1 for every key that appears more than once.

  if(overusedWordCount[word]){

     overusedWordCount[word]++;

  }else{

     overusedWordCount[word] = 1;

  }

});

  return overusedWordCount; 

};

console.log(getFrequency(overusedWordArray));

My log shows

[‘basically’,
‘really’,
‘very’,
‘very’,
‘very’,
‘very’,
‘very’ ]
[ really: 2, basically: 1, very: 5 ]

but here is the kicker I cant find a way to remove the brackets. I have tried .join() on the returned array, reassigning the array to the array with .join, and even assigning a new variable to the array with .join but no luck!

that’s wierd… You should be able to join the array. did you set it with space in between like below?

array.join(' ');

I tried your code snippet in my project after customising it and it worked perfectly :smiling_face_with_three_hearts: :smiling_face_with_three_hearts: