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 fibonacci = (function ( ) { | |
var memo = [0, 1]; | |
var fib = function (n) { | |
var result = memo[n]; | |
if (typeof result !== 'number') { | |
result = fib(n - 1) + fib(n - 2); | |
memo[n] = result; | |
} | |
return result; | |
}; |
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.prototype.method = function (name, func) { | |
if (!this.prototype[name]) { | |
this.prototype[name] = func; | |
return this; | |
} | |
}; | |
Function.method('curry', function () { | |
var slice = Array.prototype.slice, | |
args = slice.apply(arguments), |
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.prototype.method = function (name, func) { | |
if (!this.prototype[name]) { | |
this.prototype[name] = func; | |
return this; | |
} | |
}; | |
String.method('deentityify', function ( ) { | |
var entity = { |
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 fade = function (node) { | |
var level = 1; | |
var step = function ( ) { | |
var hex = level.toString(16); | |
node.style.backgroundColor = '#FFFF' + hex + hex; | |
if (level < 15) { | |
level += 1; | |
setTimeout(step, 100); | |
} | |
}; |
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 myObject = function () { | |
var value = 0; | |
return { | |
increment: function (inc) { | |
value += typeof inc === 'number' ? inc : 1; | |
}, | |
getValue: function() { | |
return value; | |
} |
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 hanoi = function hanoi(disc, src, aux, dst) { | |
if (disc > 0) { | |
hanoi(disc - 1, src, dst, aux); | |
console.log('Move disc ' + disc + | |
' from ' + src + ' to ' + dst); | |
hanoi(disc - 1, aux, src, dst); | |
} | |
}; | |
hanoi(3, 'Src', 'Aux', 'Dst'); |
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 add = function (a, b) { | |
return a+b; | |
} | |
var arr = [3,7]; | |
var sum = add.apply(null, arr); | |
console.log(sum); |
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 add = function (a, b) { | |
return a+b; | |
} | |
console.log(add(7,3)); |
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 Quo = function (string) { | |
this.status = string; | |
}; | |
var myQuo = new Quo("confused"); | |
console.log(myQuo); |
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 myObject = { | |
value: 0, | |
increment: function (inc) { | |
this.value += typeof inc === 'number' ? inc : 1; | |
} | |
}; | |
myObject.increment( ); | |
console.log(myObject.value); |