Created
March 15, 2017 14:06
-
-
Save leovolving/21afd1364420f890727785df68abc0d5 to your computer and use it in GitHub Desktop.
2.6.6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Lines 1-4: A function that takes a string and removes the special characters and upper case letters so that may be attached to a word. | |
Line 6: Begins the function | |
Line 7: Runs the text inputted into the function into the getTokens function so that everything is lowercase and the special characters are removed. The result will be a new variable which will be used for the mostFrequentWord function | |
Line 8: Creates an empty object in which all of the words will be placed | |
Lines 9-16: A function in which each word in the variable "words" will be passed through. If that word is not already a key in the object wordFrequencies, the value will be 1. If the word is already in wordFrequencies, the value will be +=1. | |
Line 17: a new variable in which we will store the word with the most frequent iterations from the object wordFrequencies | |
Line 18: A new variable which keeps track of the current "maximum word" based on the object key | |
Lines 19-25: We loop over the object. If the current word in the loop is more frequent than the "current max count", the current word becomes the "current max count" | |
Line 26: Return the most frequent word |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment