Function bCompare($a, $b, $c) {
return !!((($a > $b) | ($a >= $b)) | (($a < $b) | ($a =< $b)) | (($a == $b) | ($a != $b)))
}
Points to whomever can tell me what that does. (I promise it works)
Click the link to see what it does…
My boss showed this to me as an “interview question” over lunch today. It is elegant and Zazen code. Ponies for Blewis. It’s his answer to the prompt: Develop a function that accepts three parameters: $a = Int, $b = int, $c = string containing a logical operand. It needs to return a boolean True or False. That’s some of the coolest, densest code I’ve ever seen.
Of course you could do it with the tertiary operator (which is how I answered the question, btw) but Blewis’ code above is far far faster.
Hopefully here in the next few weeks I’ll be able to publish my one-liner javascript that uses Haptic data to determine if a web request is really a human being or a bot (making captcha’s unnecessary) Until then, enjoy drawing the truth table for the above line.
Jared | August 6th, 2008 at 11:23 pm #
granted i’m not all cool and zen-like with the coding… …and, as the hack i am, prefer to code in whatever manner is most human readable over what is necessarily most efficient (to a point, anyway)…
Most of what i see there makes sense to me - in that the operations are familiar - but their arrangement is lost on me i’m afraid, so i don’t know what it ‘does’. Do i get an explanation?