Created
August 31, 2011 15:14
-
-
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")
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.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()); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!