Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The get tokens function is used to return the raw string arguement to lower case and splits the string into a sorted string
- based on the regular expression. Most frequent word accepts one arguement, the body of text and passes it to the raw string
- function and assigns it to the variable words. The next line declares an empty object called word frequency. The next line
- is the beginning of a for loop that loops through the word variables contents, I believe that the contents are an array, my
- thought now is that the raw string function actually returns an array that has been seperated into individual words by using
- the regular expression. The if statement within the for loop checks to see if the word exsists in the word frequency object,
- if it does then it increments a word property to which represents how many times the word has occured. The else statement
- 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
- a variable current max count and sets the variable to value of the key of the first key value. The next line assigns
- 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
- for loop that iterates over word frequency and compares to current max count. If the current value of word frequency is
- greater then current max count then assign that word to current max key and change the value of current max count to reflect
- the change. The final line returns the value of current max key.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement