Skip to content

Instantly share code, notes, and snippets.


View GitHub Profile
View Event Listener Drills
View Analyze a most frequent word program
function getTokens(rawString) {
// NB: `.filter(Boolean)` removes any falsy items from an array
return rawString.toLowerCase().split(/[ ,!.";:-]+/).filter(Boolean).sort();
The above code takes the text and strips it down to lower case words with no punctuation, no chance of the counter to confuse upper and lowercase words, and to remove returns, etc as well as creating the array with the list of words.
function mostFrequentWord(text) {
let words = getTokens(text);
The above code takes the text that has been “scrubbed clean” by getTokens function
let wordFrequencies = {};
View Object Drills 2
View Object Drills
View Scope Challenge
What is scope? Your explanation should include the idea of global vs. local scope.
What a variable can do is determined by its location within the code; this is called scope.
Scope also determines the part of the program where the variable is available. JavaScript has two scopes -
global and local. If a variable is outside of a function then it is global and can be accessed from anywhere in the code.
Local scope is when variables are created inside functions and are thus also known as function scope.
Why are global variables avoided?
Global variables should be avoided because they can be changed by any part of the program.
Explain JavaScript's strict mode
View Arrays and Loops Drills
View Array Method Drills
View Array Basic Drills
View Logic Drills
View Number Drills
You can’t perform that action at this time.