Created
February 7, 2013 15:46
-
-
Save jackfranklin/4731766 to your computer and use it in GitHub Desktop.
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
/*** | |
* | |
* I want to execute someFunc() if the variable x is greater than 5 | |
* how would you rewrite the below to NOT use a conditional? (EG no "if" used) | |
* | |
* **/ | |
if(x > 5) { | |
someFunc(): | |
} |
Man, I could come up with these all day, much fun 😄
This one's pretty useless, though an interesting exercise in getting it to actually work. Relies on you not caring about the return value of someFunc.
var self = function() {
return self;
}
var first = function(fn) {
return function() {
fn();
return self;
}
}
var wrap = function(fn) {
return function() { return fn }
}
var wrapped = wrap(wrap(wrap(wrap(first(someFunc)))));
var limit = Math.max(x,1);
while(limit--) { wrapped = wrapped(); }
var foo = setTimeout(someFunc, 5); setTimeout(function() { clearTimeout(foo) }, x);
HEY JACK WHAT ABOUT x > 5 && someFunc();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm slow to seeing the tweet, but I'll comment anyway.
x > 5 && someFunc()