Skip to content

Instantly share code, notes, and snippets.

View oaluna's full-sized avatar
💭
Job hunting!

Oscar Luna oaluna

💭
Job hunting!
View GitHub Profile
@oaluna
oaluna / gist:9ae8a7940cfe78a3d70f4dbd3a7d2368
Last active October 12, 2019 15:37
Most Frequent Word Analyzer Challenge - Oscar Luna
function getTokens(rawString) {
// NB: `.filter(Boolean)` removes any falsy items from an array
return rawString.toLowerCase().split(/[ ,!.";:-]+/).filter(Boolean).sort();
}
function mostFrequentWord(text) { // this is our function that takes the argument text.
let words = getTokens(text); // this tells the computer that every true item in the text is a word
let wordFrequencies = {} //wordFrequencies is an array that iterates through the whole text.
for (let i = 0; i <= words.length; i++) {
if (words[i] in wordFrequencies) {
@oaluna
oaluna / gist:baab4dd4e72b6b7eaa7b7bb7d0ee1d9a
Created October 8, 2019 23:32
Variable Scope Questions
Scope is what defines a variable's access throughout certain parts of a code. If a variable's definition is within a block of instructions (like a function), then this variable is said to have block scope; its value can only be accessed within the block of instructions. If defined outside of a block of instructions, a variable is defined in the global scope, where its value can be accessed anywhere it is invoked. Whenever a definition is unavailable within the block scope, JavaScript will search up the scope chain, through parent scopes of a variable's function, for a definition. Variables declared at the global scope can be troublesome for this reason because it can lead to parent values being altered when running a code and make a function intederminate; it won't return the same value given the same input. Strict mode is a command that, when placed at the top of a JavaScript file, requires a contributor to use let or const when declaring a variable. Not doing so in Strict Mode will return an 'uncaught ref