Created
June 15, 2011 18:53
-
-
Save Rob-ot/1027804 to your computer and use it in GitHub Desktop.
javascript tilde operator with indexOf
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
> var a = ["a", "b"] | |
> a.indexOf("a") | |
0 | |
> a.indexOf("b") | |
1 | |
> a.indexOf("c") | |
-1 | |
> ~a.indexOf("a") | |
-1 | |
> ~a.indexOf("c") | |
0 | |
> !!~a.indexOf("a") | |
true | |
> !!~a.indexOf("c") | |
false |
^^
Since then,
Most browsers perform these much faster and equally as fast too.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Firefox:
a: 232ms
b: 95ms
Chrome:
a: 265ms
b: 152ms
Just saying...