daily pastebin goal
43%
SHARE
TWEET

Untitled

a guest Nov 12th, 2018 105 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. The first function in the code, getTokens, is used to remove punctuation from the paragraph and organize. It does this by first
  2. making all the letters lower case, splitting the whole thing without punctuation characters, removes falsy items
  3. with filter, and then sorts the words alphabetically.
  4.  
  5. The second function, mostFrequentWord, starts by defining words by running the getTokens function. This sorts the
  6. text. They then define wordFrequencies as an object. Using a for loop they loop through the sorted text and add
  7. each word as a key to the empty wordFrequencies object. If the word is already in the object it adds 1 to the value.
  8. If the word only appears once it is automatically given the value of 1.
  9.  
  10. Next they define currentMaxKey as the first key in wordFrequencies by using Object.keys. currentMaxCount is
  11. then defined as the value of the first key in wordFrequencies.
  12.  
  13. Next they loop through wordFrequencies. If a word has a higehr value than currentMaxCount then currentMaxKey is
  14. redefined as that word and that word's value in wordFrequencies becomes the value of currentMaxCount. After
  15. wordFrequencies has been completely looped through the function returns currentMaxKey or the word with the highest
  16. currentMaxCount.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top