Created
February 17, 2019 22:51
-
-
Save rtanubra/becd21865ed79802427284fbedede854 to your computer and use it in GitHub Desktop.
Module 4, Checkpoint 12
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
https://repl.it/@ReyTanubrata/Make-student-reports-drill | |
https://repl.it/@ReyTanubrata/Enroll-in-summer-school-drill | |
https://repl.it/@ReyTanubrata/find-by-id-drill | |
https://repl.it/@ReyTanubrata/validate-object-keys-drill | |
Grokking | |
function getTokens() | |
-input: raw string (with weird characters perhaps in a paragraph) | |
-method: | |
-convert all alphabet characters to lower case | |
-splits on [ ,!.";:-] meaning "I love this! STuff" => ["i","love","this","stuff"] | |
-output: | |
-array of words. | |
-words are in lower case | |
-all non alphanumeric characters have been removed | |
function mostFrequentWords | |
-starts with an empty dictionary. | |
-Build a word count dictionary (wordFrequencies) | |
-iterates through the array of words with following: | |
-if the word exists in dictionary add 1 to the word count | |
-else add word to dictionary with count of 1 | |
-Now find the word with the largest count | |
-start with an intial currentMaxCount of first word in dictionary | |
-start with an initial currentMaxKey as the first word in the dictionary | |
-iterate through the dictionary with Object.keys(<my_object>) | |
-if current word count > currentMaxCount | |
- currentMaxCount is replaced with current word count | |
- currentMaxKey is replaced with the current word | |
-else continue iterating. | |
-after iterating through the object list we will have the currentMaxKey as the word that appears most frequently in text | |
- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment