Skip to content

Instantly share code, notes, and snippets.

@ryanbsherrill
ryanbsherrill / cat carousel
Created March 11, 2017 07:37
Event Listener Drills
@ryanbsherrill
ryanbsherrill / wordProblem.js
Created February 27, 2017 04:37
analyze a most frequent word problem
/* GET TOKENS: this function takes a 'raw string' and 'gets'/organizes every
character and word in 'alphabetical order' inside of an array. each of the words
and chars which were once part of a single string have now been given their own
index positions */
function getTokens(rawString) {
// NB: `.filter(Boolean)` removes any falsy items from an array
return rawString.toLowerCase().split(/[ ,!.";:-]+/).filter(Boolean).sort();
}
// mostFrequentWord is a function that takes a string of text as its argument
.map:
https://jsbin.com/yowisob/edit?js
for loop:
https://jsbin.com/yowisob/edit?js
@ryanbsherrill
ryanbsherrill / deleting keys
Created February 24, 2017 07:25
object drills
https://jsbin.com/wiruzez/edit?js
@ryanbsherrill
ryanbsherrill / Challenge: In Your Own Words
Created February 24, 2017 06:15
Scope and the Problem with Globals
Scope refers to the regions of your code in which your variables can be accessed. If a variable is within
the global scope, it means that it can be accessed from any other place in your program. If a variable is
local to a function, that means that it can only be accessed by the code inside the block of that function.
Global variables are avoided because they can cause all kind of unintended side effects. These side
effects can cause parts of your program to produce different results when given the exact same inputs,
which is obviously not a good thing.
Strict mode forces the user to be more careful with their syntax by throwing errors where the code
would normally just run. Things such as: if a function parameter name were not unique within whole of the
@ryanbsherrill
ryanbsherrill / FizzBuzz
Created February 24, 2017 03:11
arrays and loops drills
https://jsbin.com/bumocas/edit?js
https://jsbin.com/bicegoh/edit?js
@ryanbsherrill
ryanbsherrill / error alert link
Created February 22, 2017 18:41
Logic Drills
@ryanbsherrill
ryanbsherrill / areaOfRectangle.js
Created February 22, 2017 00:38
number drills
// Area of a Rectangle
function computeArea(width, height) {
return width * height;
}
function testComputeArea() {
var width = 3;
var height = 4;
var expected = 12;