Mini Linter - Step 8


#1

I’m struggling to find a solution for step 8 - second task.

I did:

let frequency = {};  
let max = 0;  
let result;   

    for(var v in betterWords) {
       word = betterWords[v].toLowerCase();
       frequency[word] = (frequency[word] || 0) + 1; // increment frequency.
       if(frequency[word] > max) {  
         max = frequency[word];  
         result = word;          
       }
}

console.log(`The word that appears most is: ${result}, ${max} times more precisely.`);

this gives me the most frequent word, but not the right amount… it says 13 and not 14. I’m not able to include in the counting this

…called "The 9W to …

I guess it is because there’s a double quote “attached” to it.

Could anyone give a hint of how to sort this out?

Cheers!


#2

Note below the use of the keyword, of which iterates the values in the array, and the use of the built-in string method, replace:

for (let word of betterWords) {
  word = word.toLowerCase().replace('"', '');
The word that appears most is: the, 14 times more precisely.

#3

It worked. Thank you so much!


#4

Ok…back again…

Step 8, task 3. After 3 days I still can’t get it right.

I’ve seen some solutions, but I cannot understand a single line of what they mean. So I tried my way simpler(?) I don’t know… but almost works.

for (let storyWordsIndex = 0; storyWordsIndex < storyWords.length; storyWordsIndex++) {
  for (let overIndex = 0; overIndex < overusedWords.length; overIndex++) { 
    if (storyWords[storyWordsIndex] === overusedWords[overIndex]) { 
    storyWords.splice(storyWords[storyWordsIndex], 1, "REMOVED");
      storyWords[storyWordsIndex]++;
    }
  } 
}


console.log(storyWords);

Well, first of all it replaces only the first word for REMOVED, even if it doesn’t belong to the overused word array. And second, instead of replace the overused word for REMOVED ,it replaces for NaN.

I could just copy one of the solutions I’ve found, but the thing is that, like I said before, I don’t understand a single line of what they mean.

Any help/explanation is more than welcome.


#5

Given a list of overused , run through the text iterating on WHILE present in text, text.replace with a word from a replacement list.


#6

Did a search for replacement terms. Here is the SERP

https://www.google.ca/search?q=appropriate+replacements+for+"really"

overusedWords.forEach(function(x) {
    while ( betterWords.indexOf(x) > -1) {
        betterWords.splice(betterWords.indexOf(x), 1, replacements[overusedWords.indexOf(x)]);
    }
});

Tested, and appears to work (with replacements = ['', '', '']). From the above serp, create a replacements array that matches the order of the overusedWords array (corresponding elements). Looking for a suitable set of replacement words. So far so good.

I like the quotes at the top of this page…


#7

Sorry for late answer, I was away for a few days.

I’ll have a look on it. Thank you so much for your help!


#8

A post was split to a new topic: Step three and replace words


#9

This is what I used. I found parts 1 and 2 of 8 very difficult, but this worked quite well and was quite intuitive:

//Replace overusedWords with something else:
for (let storyWordsIndex =0; storyWordsIndex < storyWords.length; storyWordsIndex++) {
if (overusedWords.includes(storyWords[storyWordsIndex])) {
let i = storyWords.indexOf(storyWords[storyWordsIndex]);
storyWords[i] = “REPLACEMENT”;
}
}
console.log(storyWords.join(" "));