Yah, I know it's sneaky. It's one of the tricks I thought of when I read through the JavaScript and ECMAScript specs recently, and this is the first time I've got to put it to use. Try it: <javascript:alert(Number(Boolean(2)));void(0);>
Oh, just wondering - what might be fastest:
Code:
(( Math.floor((n%100)/10) == 1)
With one scope jump, one property lookup, one function call, one remainder, one division and one comparison, or
Code:
( this % 100 - nModTen != 10 ) * nModeTen
With one remainder, one subtraction, one comparison, one autocasting, and one multiplication.
I believe your code would win out, in those cases. (The access part (scope jump and property lookup) should be fast compared to my math, and the function call and the autocast should both be almost unnoticable) However, my single comparison should make my code faster in the cases of 'th', when I won't have to perform all those numerical operations. So, how would they compare for many numbers, performance wise?