Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- alphabetical language, such as periods, exclamation points, semi colons, etc. It uses terminology such as boolean to filter any falsy value
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- through. The function finally ends by returning the word with the largest value attached to it.
Add Comment
Please, Sign In to add comment