This file contains hidden or 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
//Javascript Currying | |
function boxes(a){ | |
return function(b) { | |
return "I like " + a + " " + b; | |
}; | |
} | |
var myboxes = boxes("my boxes"); | |
var yourboxes = boxes("your boxes"); | |
console.log("my boxes:"); |
This file contains hidden or 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 Decorator: | |
// Takes one function as an argument, returns another function. The returned function is a variation of the argument function. | |
function not (fn) { | |
return function (argument) { | |
return !fn(argument); | |
}; | |
} |
This file contains hidden or 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
// Partial Application using Map and passing in a function | |
var oldArray = [1,4,9,16,25]; | |
console.log(oldArray); | |
var newArray = oldArray.map( | |
function(n){ | |
return n*n;} | |
); | |
console.log(newArray); |
This file contains hidden or 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
console.log("========================"); | |
//Closures | |
(function(x) { | |
return function(y) { | |
return function(z) { | |
console.log("x "+x); | |
console.log("y "+y); | |
console.log("z "+z); | |
console.log(x + y + 3); | |
return x + y + z; |
This file contains hidden or 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 imgLoader = { | |
config: { | |
container: '.imgContainer', | |
images : '#images', | |
imageLoadBtn: '.loadImages', | |
defaultSplice:4, | |
url : 'http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?' | |
}, | |
imgData: [], | |
This file contains hidden or 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
//Array push / pop | |
var oneSet = [1,2,3,4]; | |
var twoSet = [5,6,7,8]; | |
var j=twoSet.length; | |
for (var i=0;i<j;i++){ | |
oneSet.push(twoSet[i]); | |
console.log(oneSet); | |
console.log(twoSet[i]); | |
} |
This file contains hidden or 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
// Simple Memoization - could use some work | |
function addMe(num){ | |
return num+num; | |
} | |
function memoMe(fn){ | |
var objs = {}; | |
return function(x){ | |
if(x in objs) | |
{ |
This file contains hidden or 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
// Simple Memoization - could use some work | |
function addMe(num){ | |
return num+num; | |
} | |
function memoMe(fn){ | |
var objs = {}; | |
return function(x){ | |
if(x in objs) | |
{ |
This file contains hidden or 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 addMe(num){ | |
return num+num; | |
} | |
function memoMe(fn){ | |
var objs = {}; | |
return function(x){ | |
return (objs[x]) ? objs[x] : (objs[x] = fn.apply(void 0, arguments), objs[x]); | |
}; | |
} |
This file contains hidden or 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
// Simple Memoization - could use some work | |
function addMe(num){ | |
return num+num; | |
} | |
function memoMe(fn){ | |
var objs = {}; | |
return function(x){ | |
if(x in objs) | |
{ |