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