8 For the overused words, remove it every other time it appears.
I even don’t know how to start.
I came up with something like that: make a new array, count overusedWords, remove overused words if they appear more than once and then throw away what’s left from story to new array. But i dont have idea how to write it.
Did you check the hint? It gives a pretty extensive hint on how to overcome to problem
i personally thought using filter and includes was a good idea, not sure though
creating a new array isn’t a bad idea, you could loop over storyWords, then loop over overusedWords to if the current word of story words equals one of the over used words, if so, do nothing, else append to your new array
The last if doesn’t work correctly and i dont know why? i tried everything: || && else/if, split on smaller if and nothing, always something is wrong.
I will try Your suggestion tomorrow, thanks btw.
Now im going to bed, my head almost exploded
bye bye
While you were busy on Number 1, I went to work on Number 2. Still don’t have it wrapped in a single function, but the proof of concept works as expected…
Write a function that finds the word that appears the greatest number of times.
why are you complicating matters so much? if you use if to check if current_word equals 'really', then use else if to check if current_word equals 'very' and another else if to check if current_word equals basically we can use else to push current_word to removeWords
For that we would need a nested loop to iterate over both words and overUsedWords. Or, build a frequency table (an object) of overUsedWords. It could get clever and include an array as a value, rather than a count. The array would contain the indexes of the found words from which removals could be determined.
Finding multiple occurences is simple enough to do with basic iteration, though JS does give us a couple of useful tools, indexOf and lastIndexOf. Combine the latter with string slicing and we can build an index of found targets
// Given earlier `story` object and these lines,
let stripped = story.split('');
let letters = stripped.filter(x => /\w|\s/.test(x)).join('');
let words = letters.split(' ');
// Build a frequency histgram of overused words
let overUsedWords = ['really', 'very', 'basically'];
const ouw_freq = {};
for (let i = 0; i < overUsedWords.length; i++) {
let word = overUsedWords[i]
let text = words.slice();
let idx, index = [];
do {
idx = text.lastIndexOf(word);
if (idx + 1) {
index.push(idx);
text = text.slice(0, idx);
}
else break;
} while (true);
ouw_freq[word] = index;
}
is not really useful, since once we start removing words this index will be useless. That suggests removing each word as we analyze it.
The neat thing is the index is in reverse so we can leave one of the first two occurences and every other after that.
if there is 1 occurence, remove it
if there are 2 then remove one
if there are 3 then remove two
if there are 4 then remove two
if there are 5 then remove three.
and so on...
Will work on an implementation of the idea and post back.
We should avoid getting addicted to tossing in variables of any sort. They do not clear the way, but clutter it.
Center on the specific object and let it become a transformation of itself wherever possible so memory leakage is kept to a minimum, AND we can keep track of what needs to be manually garbage collected afterward.
I’m not in an oppressive environment, but I know the mental challenges well. We succeed when we not only persevere, but when we ourselves become precocious beyond anyone’s control. Become yourself.
Of the husband part… Is he helping, or hindering? Ask him to stand down and advise only, not direct. In programming, we are the directors.