Skip to content

Instantly share code, notes, and snippets.

@eamodeorubio
Created August 31, 2011 15:14
Show Gist options
  • Save eamodeorubio/1183806 to your computer and use it in GitHub Desktop.
Save eamodeorubio/1183806 to your computer and use it in GitHub Desktop.
Autoejecutable cuenta 0 a 100 sin usar bucles, condicionales o expresiones booleanas (Versión "framework")
Function.prototype.then = function(callback) {
var branches = { false:function() {}, true:callback };
var that = this;
return function() {
var r = that.apply(that, arguments);
branches[r].apply(that, arguments);
return r;
}
}
Number.prototype.times = function(callback) {
(function(i) { return i != 0; }).then(function(i) {
(i - 1).times(callback);
})(this);
callback(this);
};
Number(100).times(function(i) { console.log(i.toString()); });
@eamodeorubio
Copy link
Author

A weird framework for weird problems. This time you can reuse Number.prototype.times and Function.prototype.then to solve a lot of weirds problems in a few seconds!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment