Skip to content

Instantly share code, notes, and snippets.

View Cfeusier's full-sized avatar

Clark Feusier Cfeusier

View GitHub Profile
@Cfeusier
Cfeusier / zoo.js
Last active August 29, 2015 14:08 — forked from dbc-challenges/zoo.js
var Zoo = function(animals) {
this.animals = animals;
};
Zoo.prototype = {
bipeds: function() {
return this.legFilter(2);
},
quadrupeds: function() {
return this.legFilter(4);
@Cfeusier
Cfeusier / stringify.js
Created November 26, 2014 00:56
Recursive Reimplementation of JSON.stringify
// recursive reimplementation of JSON.stringify
var stringifyJSON = function(obj) {
// null
if (obj === null) {
return "null";
}
// unstringifiable - functions and undefined
if (obj === undefined || obj.constructor === Function) { return; }
@Cfeusier
Cfeusier / get_elements_by_class_name.js
Last active May 3, 2016 02:15
Recursive Reimplementation of document.getElementsByClassName
var getElementsByClassName = function(className, node) {
var matches = [];
// top of node tree or default to body
node = node || document.body;
// get all classNames of node
var nodeClasses = node.className.split(" ");
// push node if node has className in classList
@Cfeusier
Cfeusier / parse.js
Created December 1, 2014 02:24
Recursive Descent Parser Reimplementation
var parseJSON = function(json) {
// setup
var idx = 0;
var cc = ' ';
var escapee = {
'"': '"',
'\\': '\\',
'/': '/',
b: '\b',
@Cfeusier
Cfeusier / prototypal-class.js
Last active August 29, 2015 14:11
Example of the Prototypal 'Class' Pattern in JavaScript
var Example = function() {
var example = Object.create(exampleMethods);
example.extraProp1 = "Example Property Value";
return example;
};
var exampleMethods = {
exampleGet: function() {
return this.extraProp1;
},
@Cfeusier
Cfeusier / functional-class.js
Last active August 29, 2015 14:11
Example of the Functional 'Class' Pattern in JavaScript
var Example = function() {
var example = {};
var extraState = "Example Property Value";
example.exampleGet = function() {
return extraState;
};
example.exampleSet = function(value) {
extraState = value;
@Cfeusier
Cfeusier / functional-shared-class.js
Created December 14, 2014 05:56
Example of the Functional-Shared 'Class' Pattern in JavaScript
var Example = function() {
var example = {};
example.extraProp1 = "Example Property Value";
_.extend(example, exampleMethods); // requires _ library or implement your own extend function
return example;
};
var exampleMethods = {
exampleGet: function() {
return this.extraProp1;
@Cfeusier
Cfeusier / pseudo-classical-class.js
Last active June 14, 2017 07:50
Example of the Pseudo-Classical 'Class' Pattern in JavaScript
var Example = function() {
this.extraProp1 = "Example Property Value";
};
Example.prototype.exampleGet = function() {
return this.extraProp1;
};
Example.prototype.exampleSet = function(value) {
this.extraProp1 = value;
@Cfeusier
Cfeusier / hashTable.js
Last active May 14, 2018 20:47
Hash Table implementation in JavaScript
var HashTable = function() {
this._limit = 8; // choose any size of hash table bucket limit
this._count = 0;
this._storage = [];
};
HashTable.prototype.insert = function(k, v) {
var i = this._getHashIndex(k, this._limit);
this._checkLimit(i); // make sure hashidx is in bounds
var bucket = this._storage[i];
@Cfeusier
Cfeusier / simple-tree.js
Created December 14, 2014 09:13
Simple Tree implementation in JavaScript
var Tree = function(value) {
var newTree = {};
newTree.value = value;
newTree.children = [];
_.extend(newTree, treeMethods);
return newTree;
};
var treeMethods = {};