Skip to content

Instantly share code, notes, and snippets.

View lawstonwalker's full-sized avatar

lawstonwalker

View GitHub Profile
I believe the function getTokens formats the text in such a way that the individual words can be run through the mostFrequentWord function. So we declare the variable words equal to the text being run through the getTokens function. This allows us to iterate through variable words, creating object wordFrequencies that gives a key for each word and a value equal to the number of frequencies of each of those words in the variable words. Variable currentMaxKey is then declared, it would seem, as an array of all the keys in object wordFrequencies, and variable currentMaxCount is declared. I get a bit lost on the how here - the phrasing in the program is a bit confusing to me - , but I believe the next loop cycles through the array that was made and updates the current max key, which is then returned as the answer to the most frequent word challenge
What is scope? Scope refers to the visibility of a variable within a JS document, and what parts of that program are able to utilize the variable in a funcion. Global scope includes the area outside all functions. When a variable is declared in the global scope of a document, it can be subject to alteration and cause side effects and indeterminant functions. Block scope is the scope within a function itself. When a variable is declared within a function, it can only be used and applied within the area of that function.
Why are global variables avoided? Global variables are meant to be avoided in order to make code more determinant. When working on a project with a team of people and variables are declared in the global scope of a document, the variables could be redefined or mutated later in the JS, which could lead to unintended side effects and errors, and also makes the code more difficult to de-bug.
Explain JavaScript's strict
https://repl.it/@lawstonwalker/text-normalizer-drill
https://repl.it/@lawstonwalker/shouter-drill
https://repl.it/@lawstonwalker/Wiseperson-generator-drill-1
https://repl.it/@lawstonwalker/area-of-a-rectangle-drill
https://repl.it/@lawstonwalker/temperature-conversion-drill
https://repl.it/@lawstonwalker/Is-divisible-drill
https://repl.it/@lawstonwalker/Error-alert-drill
https://repl.it/@lawstonwalker/Traffic-lights-drill