a guest Nov 12th, 2018 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- The first function in the code, getTokens, is used to remove punctuation from the paragraph and organize. It does this by first
- making all the letters lower case, splitting the whole thing without punctuation characters, removes falsy items
- with filter, and then sorts the words alphabetically.
- The second function, mostFrequentWord, starts by defining words by running the getTokens function. This sorts the
- text. They then define wordFrequencies as an object. Using a for loop they loop through the sorted text and add
- each word as a key to the empty wordFrequencies object. If the word is already in the object it adds 1 to the value.
- If the word only appears once it is automatically given the value of 1.
- Next they define currentMaxKey as the first key in wordFrequencies by using Object.keys. currentMaxCount is
- then defined as the value of the first key in wordFrequencies.
- Next they loop through wordFrequencies. If a word has a higehr value than currentMaxCount then currentMaxKey is
- redefined as that word and that word's value in wordFrequencies becomes the value of currentMaxCount. After
- wordFrequencies has been completely looped through the function returns currentMaxKey or the word with the highest
RAW Paste Data