Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. The get tokens function is used to return the raw string arguement to lower case and splits the string into a sorted string
  2. based on the regular expression. Most frequent word accepts one arguement, the body of text and passes it to the raw string
  3. function and assigns it to the variable words. The next line declares an empty object called word frequency. The next line
  4. is the beginning of a for loop that loops through the word variables contents, I believe that the contents are an array, my
  5. thought now is that the raw string function actually returns an array that has been seperated into individual words by using
  6. the regular expression. The if statement within the for loop checks to see if the word exsists in the word frequency object,
  7. if it does then it increments a word property to which represents how many times the word has occured. The else statement
  8. adds the word to the object and increments its value to one and only runs if the word does not exist. The next line declares
  9. a variable current max count and sets the variable to value of the key of the first key value. The next line assigns
  10. current max count to the value stored in word frequency at the key found in the previous line. The final block of code is a
  11. for loop that iterates over word frequency and compares to current max count. If the current value of word frequency is
  12. greater then current max count then assign that word to current max key and change the value of current max count to reflect
  13. the change. The final line returns the value of current max key.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement