Skip to content

Instantly share code, notes, and snippets.

@cmstead
cmstead / curry.js
Created October 17, 2014 17:26
Currying example in JS
(function(){
var collection = [1, 2, 3, 4, 5, 6, 7],
add10,
newCollection;
function map(passedCollection, userFn){
var newCollection = [];
passedCollection.forEach(function(value){
//Write a function that compares two values and returns true if they are a match and false if they are not.
function compare(x,y)
{
var temp1 = typeof(x);
var temp2 = typeof(y);
if(temp1 == temp2)
/*
* If you want to extend your ES5 objects with less ceremony, here's a function you can use to make your
* life a little easier. I originally included this in the post, but added too much information and
* not enough clarity. This may not be the best way to solve our problem, but it illuminates the process
* of automating inheritance to abstract it from your logic.
*
* This accompanies the blog post: http://www.chrisstead.com/archives/705/mainstay-monday-inheritance/
*/
function extends(child, parent){
@cmstead
cmstead / gist:1ab28f1e30f9d6d43218
Last active August 29, 2015 14:26
Proof that P && !P (apenantology) is always false
//I propose an apenantology can be represented as P && !P such that this expression is always false
//Proof
P || !P // Tautology, always true
=> !(P || !P) // Inverse of tautological statement, always false
=> !P && P // Distributive property of &&
=> P && !P // Commutitive property of &&
=> P && !P <=> false
QED
@cmstead
cmstead / keyed-object-sort.js
Last active September 19, 2015 20:52
Sort factory supporting array of columns and SQL-like ascending/descending sorting
// Full sorting factory with SQL-like ascending and descending sort functionality
var keyedSortFactory = (function(){
'use strict';
function keyedSort(sortArray, a, b){
var result = 0,
index = 0,
sortArrayLength = sortArray.length;
while(result === 0 && index < sortArrayLength){
@cmstead
cmstead / linked-list-factory.js
Created September 20, 2015 19:36
A linked list factory in Javascript
var listItemFactory = (function(){
'use strict';
function ListItem(value){
this.value = value;
this.nextPointer = null;
}
ListItem.prototype = {
val: function(){
@cmstead
cmstead / queue-factory.js
Created September 20, 2015 19:49
A queue factory in Javascript
var queueFactory = (function(){
'use strict';
function Queue(){
this.queueHead = null;
this.queueLast = null
}
Queue.prototype = {
getHeadValue: function(){
@cmstead
cmstead / request-cache-factory.js
Created September 20, 2015 19:49
Request cache factory in Javascript
var cacheFactory = (function(){
'use strict';
function RequestCache(requestFn){
this.callQueue = queueFactory.build();
this.requestFn = requestFn;
this.dataCache = {
requestSent: false,
response: null
@cmstead
cmstead / j.clone.source.js
Created October 24, 2015 20:15
Clone method from JFP 2.4.0
function clone (originalValue, depth) {
var depthOkay = j.isUndefined(depth) || j.geq(depth, 0),
copyOkay = j.isType('object', originalValue) || j.isType('array', originalValue);
function copy () {
var keys = Object.keys(originalValue),
container = j.isArray(originalValue) ? [] : {};
j.each(function (key) {
var newDepth = j.isNumber(depth) ? depth - 1 : undefined;