Skip to content

Instantly share code, notes, and snippets.

@mzibari
Created January 23, 2020 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzibari/e3a045a2051b0c3086481d29459066eb to your computer and use it in GitHub Desktop.
Save mzibari/e3a045a2051b0c3086481d29459066eb to your computer and use it in GitHub Desktop.
We start with the function "getTokens", which takes a single argument "rawString". it will change all letters to lower case letters, since java script is case sensative, when we compare the amount of times a particular word has occured, we don't want the word "This" be considered a diffirent word from "this". Then the function will remove all symboles and return all the words as an array of strings. In our code, the returned array will be stornd in "words" array.
We then create an object "wordFrequencies" that we will later use to store all unique words as keys, and the frequency of thoses keys as thier values.
After that, we itirate through the "words" array using a for loop, counting each occurance of words and storing that information in our "wordFrequencies" object.
In the last part, we use a for(...in...) loop to determine which key has the largest frequency, and based on that result, we return the key of the most frequent word.
There's a more detailed line by line description of the code in the link below
https://repl.it/@MZibari/most-frequent-word-analyzer-challenge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment