Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. Line one creates a starter function. It takes one input which is likely going to be a string.
  2.  
  3. Then it returns the modified input, in this case it makes the string lowercase, splits it into an array,
  4. then takes out whatever they don't want in the string, and finally it is sorted.
  5.  
  6. The second function also takes one string input.
  7. It declares a variable that calls the first function. Then an object called wordFrequencies is declared.
  8. A for loop iterates through the words array.
  9. An if statement is created to see if a word in the word array matches the word in the wordFrequencies object.
  10. If it does go to the next index after words[i]. Otherwise, it is given a 1 value.
  11.  
  12. Two more variables are declared. One is given the value of the first index of the wordFrequencies object.
  13. The other one is set to equal the above variable. A for in loops through the object.
  14. If the value of wordFrequencies[word] (from the last function) is greater than the currentMaxCount.
  15. (which was set to 0) Then the currentMaxKey is set to the word, and the currentMaxCount is set
  16. to the wordFrequencies at the value of word. Then the function returns the currentMaxKey.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement