Guest User

Untitled

a guest
May 24th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. From lines 1-3, the point of that code is essentially to separate all the words in a given text alphabetically while getting rid of all non
  2. alphabetical language, such as periods, exclamation points, semi colons, etc. It uses terminology such as boolean to filter any falsy value
  3. out of the array. At the end of that function, a long text would be reduced to an array of each word from the text arranged in alphabetical
  4. order. Starting from line 7, line 7 basically calls the above function, while line 8 creates an empty object with no keys or values. The for
  5. loop with nested if loops basically goes through the entire array of words created in line 7 and places them into the object made in line 8
  6. with the words being the keys, and a number being the value. The if statement basically says that if the chosen word in the array for loop
  7. statement is already in the object, add 1 to its value, and if not, create a new key for the word and set its value to 1. The function then
  8. goes on to in line 16-17 to define both a temporary key and value, sets both to the beginning word in the wordFrequency object, and from
  9. 19-22, loops through the list of keys in the wordFrequency object using the Object.keys method. If it finds a key that points to a value larger
  10. than the one it currently has set as its largest value, it changes its value to match that larger value, otherwise it just continues to loop
  11. through. The function finally ends by returning the word with the largest value attached to it.
Add Comment
Please, Sign In to add comment