Created
October 23, 2017 19:02
-
-
Save goldtreefrog/3509d2748780587ecf53cec94ba31ede to your computer and use it in GitHub Desktop.
Analysis of 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
The mostFrequentWords() function passes a string to the getTokens() function, which | |
splits it into an array of words, returning that to mostFrequentWords(), which saves | |
it into the "words" array. mostFrequentWords() then tabulates each word in the array, | |
storing the results in an object array called wordFrequencies, within which each | |
unique word is a key with a value corresponding to the number of times the word was | |
encountered in the | |
"words" array. | |
The function then loops through the wordFrequences array to find the word | |
with the highest number of occurrences, comparing each count to the highest | |
found so far that is stored in the variable, currentMaxCount. It stores the | |
corresponding word in currentMaxKey. The function returns the word that ends up | |
in currentMaxKey when it has finished comparing all word counts. | |
Since the function only stores a single word, if it finds another word with | |
the same highest word count, it ignores it and just returns the first one. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment