Created
May 12, 2016 18:33
-
-
Save ianmstew/2d4ebcd55bb70935c9c4475ee0cd62da to your computer and use it in GitHub Desktop.
The best way to test the truthiness of a boolean
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
function testBoolean(boolean) { | |
var booleanCharArray = (function (str){ | |
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char | |
var bufView = new Uint16Array(buf); | |
for (var i=0, strLen=str.length; i<strLen; i++) { | |
bufView[i] = str.charCodeAt(i); | |
} | |
return buf; | |
}(String(!!!!!!!boolean))); | |
return ( | |
booleanCharArray[0] === 116 && | |
booleanCharArray[1] === 114 && | |
booleanCharArray[2] === 117 && | |
booleanCharArray[3] === 101 | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment