A Pen by Chris Stead on CodePen.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var collection = [1, 2, 3, 4, 5, 6, 7], | |
add10, | |
newCollection; | |
function map(passedCollection, userFn){ | |
var newCollection = []; | |
passedCollection.forEach(function(value){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var listItemFactory = (function(){ | |
'use strict'; | |
function ListItem(value){ | |
this.value = value; | |
this.nextPointer = null; | |
} | |
ListItem.prototype = { | |
val: function(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var queueFactory = (function(){ | |
'use strict'; | |
function Queue(){ | |
this.queueHead = null; | |
this.queueLast = null | |
} | |
Queue.prototype = { | |
getHeadValue: function(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cacheFactory = (function(){ | |
'use strict'; | |
function RequestCache(requestFn){ | |
this.callQueue = queueFactory.build(); | |
this.requestFn = requestFn; | |
this.dataCache = { | |
requestSent: false, | |
response: null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
OlderNewer