Skip to content

Instantly share code, notes, and snippets.

View zbigniewTomczak's full-sized avatar

zbigniewTomczak

View GitHub Profile
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;
};
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),
Function.prototype.method = function (name, func) {
if (!this.prototype[name]) {
this.prototype[name] = func;
return this;
}
};
String.method('deentityify', function ( ) {
var entity = {
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);
}
};
var myObject = function () {
var value = 0;
return {
increment: function (inc) {
value += typeof inc === 'number' ? inc : 1;
},
getValue: function() {
return value;
}
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');
var add = function (a, b) {
return a+b;
}
var arr = [3,7];
var sum = add.apply(null, arr);
console.log(sum);
var add = function (a, b) {
return a+b;
}
console.log(add(7,3));
var Quo = function (string) {
this.status = string;
};
var myQuo = new Quo("confused");
console.log(myQuo);
var myObject = {
value: 0,
increment: function (inc) {
this.value += typeof inc === 'number' ? inc : 1;
}
};
myObject.increment( );
console.log(myObject.value);