Skip to content

Instantly share code, notes, and snippets.

@juandopazo
Created August 30, 2011 22:14
Show Gist options
  • Save juandopazo/1182244 to your computer and use it in GitHub Desktop.
Save juandopazo/1182244 to your computer and use it in GitHub Desktop.
JavaScript without logical operators or loops
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);
});
}
@dciccale
Copy link

dciccale commented Mar 7, 2012

eaa! se podía jaja congratz

@b2whats
Copy link

b2whats commented Apr 6, 2016

it's great

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