Skip to content

Instantly share code, notes, and snippets.

@goldtreefrog
Created October 23, 2017 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goldtreefrog/3509d2748780587ecf53cec94ba31ede to your computer and use it in GitHub Desktop.
Save goldtreefrog/3509d2748780587ecf53cec94ba31ede to your computer and use it in GitHub Desktop.
Analysis of Frequent Word Program
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