Created
August 30, 2018 08:19
-
-
Save ecarlson1201/a0ef4b3508b2b382e89481d0b5bb570a to your computer and use it in GitHub Desktop.
Analyze most frequent word program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* After removing any falsey items from the raw text using the getTokens function, we are left with one clean | |
lower case string containing only words seperated by spaces. The mostFrequentWord function takes that string | |
and assigns it to a variable, words. The function then iterates through each word and if it encounters a new | |
word it adds one to a new key in an object, wordFrequencies. If it has already encountered the word, it adds | |
one to the key at which it first encountered the word. | |
Afterwards, it sets a variable, currentMaxKey, to the first word in the wordFrequencies object and another | |
variable, currentMaxCount, to whatever index of the currentMaxKey in the wordFrequencies object. | |
Next the function iterates over every property in the wordFrequencies object. It then runs an if statement | |
stating if the current iteration in the object is greater than the currentMaxCount variable, it sets the | |
currentMaxKey as the value at the current iteration and the currentMaxCount at the iteration number itself. | |
Once it runs through the entire string, it returns the currentMaxKey, thus giving us the word that has | |
been found the most. */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment