Skip to content

Instantly share code, notes, and snippets.

View TessMyers's full-sized avatar

Tess Myers TessMyers

View GitHub Profile
@TessMyers
TessMyers / gist:a252520dd9a8fe68f8e5
Last active December 10, 2024 21:29
Simple exercises using .map and .reduce
// Simple problems to solve using the native .reduce and .map array methods. Each of these problems can be solved in many
// different ways, but try to solve them using the requested higher order function.
// MAP
// Write a function capitalize that takes a string and uses .map to return the same string in all caps.
// ex. capitalize('whoop') // => 'WHOOP'
// ex. capitalize('oh hey gurl') // => "OH HEY GURL"
var capitalize = function(string){
// code code code!
{"type":"match","offset":0,"text":"(a|b)","body":[
{"type":"capture-group","offset":1,"text":"a|b","body":
{"type":"alternate","offset":1,"text":"a|b","left":
{"type":"match","offset":1,"text":"a","body":[
{"type":"literal","offset":1,"text":"a","body":"a","escaped":false}
]},"right":
{"type":"match","offset":3,"text":"b","body":[
{"type":"literal","offset":3,"text":"b","body":"b","escaped":false}
]}
},"index":1},
@TessMyers
TessMyers / hashTableWithRemove.js
Last active August 29, 2015 14:08
simple HashTable example
// This is an example of a simplified javascript hash table that showcases a neat way (ln 64) to remove entries without
// unneccesary iteration and without leaving undefined values lying around.
// I was too lazy to write a real hashing function, so just pretend that the hash function shown at the bottom works perfectly
var makeHashTable = function(){
var result = {};
result.storage = [];
var storageLimit = 10;
@TessMyers
TessMyers / gist:31aaf38de1de4b9be40a
Created October 31, 2014 06:14
Pseudoclassical instantiation
// This function does not return anything, but instead creates a new instance of an object with
// the given attributes when the "new" keyword is used.
var Cat = function(){
this.stomach = [];
};
// adds methods to the prototype for this new cat object
Cat.prototype.meow = function(){
console.log("MEOWPURR");
};
@TessMyers
TessMyers / gist:ddb7fa580cbb4034b6e0
Created October 31, 2014 05:47
Prototypal instantiation
// Creates a basic cat with meow and eat methods, then creates a kitten object that inherits from
// Makes cats with meow and eat methods, plus a stomach (just for hairballs)
var makeCat = function(name){
var cat = Object.create(catMethods);
cat.stomach = [];
return cat;
};
@TessMyers
TessMyers / gist:e7d2c28ec2d881ef9d65
Last active August 29, 2015 14:08
Functional instantiation with shared methods
// Makes two animals that have their own animal sound methods, but share a common .eat method
var makeCat = function(){
var cat = {};
cat.stomach = [];
cat.meow = function(){
console.log("MEOW");
};
_.extend(cat, animalMethods);
var makeCat = function(){
var cat = {};
cat.stomach = [];
cat.meow = function(){
console.log("MEOW");
};
cat.eat = function(food){
cat.stomach.push(food);
### Keybase proof
I hereby claim:
* I am tessmyers on github.
* I am tessmyers (https://keybase.io/tessmyers) on keybase.
* I have a public key whose fingerprint is D6EB 9A97 99A7 EFAC 31CB 1D9B 6AAD E366 07AD 4048
To claim this, I am signing this object:
var checkPassword = function() {
var query = prompt("what's the password?");
if(query === "password"); {
alert("Awesomesauce, that's right!");
} else {checkPassword()}
}
}
}