Created
August 30, 2011 22:14
-
-
Save juandopazo/1182244 to your computer and use it in GitHub Desktop.
JavaScript without logical operators or loops
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 _if(truthy, then) { | |
[then, function () {}][+!truthy](); | |
} | |
function ifElse(truthy, then, _else) { | |
[then, _else][+!truthy](); | |
} | |
function and(a, b) { | |
return !!((!!a + !!b) >> 1); | |
} | |
function or(a, b) { | |
return !!(!!a + !!b); | |
} | |
function _for(from, cond, augment, fn) { | |
var i = from; | |
_if(cond(i), function step() { | |
fn(i); | |
i = augment(i); | |
_if(cond(i), step); | |
}); | |
} | |
function _while(cond, fn) { | |
_if(cond(), function () { | |
fn(); | |
_while(cond, fn); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
eaa! se podía jaja congratz