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
// from: http://dis.4chan.org/read/prog/1295544154/170 | |
function sleepSort(list, callback) { | |
var result = []; | |
list.forEach(function(i) { | |
setTimeout(function() { | |
result.push(i); | |
if(result.length == list.length) { | |
callback(result); |
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
/** | |
* Constructor que provee de la funcionalidad | |
* de iteracion | |
* | |
* @constructor | |
*/ | |
function Iterable() {} | |
/** | |
* Excepcion utilizada para detener la iteracion |
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 deferDecorator(fn, scope) { | |
return function() { | |
var args = arguments; | |
setTimeout(function() { | |
fn.apply(scope, args); | |
}, 0); | |
} | |
} |
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
// Decora la funcion camelizando su resultado | |
function camelizeDecorator(fn) { | |
return function() { | |
return fn.apply(null, arguments).replace(/[-\s_]+(.)?/g, function(match, chr) { | |
return chr ? chr.toUpperCase() : ''; | |
}); | |
} | |
} | |
function k(a) { |
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 bindDecorator(fn, scope) { | |
return function() { | |
fn.apply(scope, arguments); | |
} | |
} | |
var o = { | |
k:function() { | |
console.log(this); | |
}, |
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 say(hey) { | |
var what = [hey]; | |
setTimeout(function() { | |
alert(what.join(' ')); | |
}, 0); | |
return function w(hey) { | |
what.push(hey); | |
return w; |
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 sacarCharRepetidos(s) { | |
return s.split('').reduce(function(memo, chr) { | |
return memo += memo.indexOf(chr) == -1 ? chr : ''; | |
}, ''); | |
} | |
function letrasFaltantes(s) { | |
return s.split('').reduce(function(memo, chr) { | |
return memo.replace(chr, ''); | |
}, 'abcdefghijklmnopqrstuvwxyz') |
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
// Iteracion implicita | |
(new Array(101)).toString().replace(/,/g, function(m, i) { | |
console.log(i) | |
}); | |
// Eval is evil! | |
eval((new Array(101)).toString().replace(/,/g, function(m, i) { | |
return ';(function() {console.log('+i+')})()'; | |
})); |
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
arr = [1,2,3,5,6,7,8,9,10] | |
arr.reduce(function(memo, current, index) { | |
return function() { | |
console.log(current); | |
memo(); | |
} | |
}, function() {})(); | |
// reduce executes the callback function once for each |
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 loop(from, to, handler) { | |
(function cycle(n) { | |
[ | |
eval, | |
function(n) { | |
handler(n); | |
cycle(n+1) | |
} | |
][1^(n/to)](n) | |
})(from); |
OlderNewer