View Single Post
Old 11-21-2012, 09:15 AM   PM User | #8
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by felgall View Post
Just one extra point - If you use 0 as the second parameter in the bind for Math.max.apply then you eliminate the possibility of the maximum being negative. That second parameter should be Number.NEGATIVE_INFINITY in order to allow the maximum to be negative.
aw man, you shoulda stopped while you're ahead; you got the ball rollin on this. i did cover the 2nd arg implications in my follow-up to Dormilich's note. or, i should say, i tried...

but, for the sake of accurate info for noobs reading this thread, i must point out that you are dead wrong about this particular point.

the 2nd param to bind (in the case of Math.max) is ignored completely, so negatives work using 0 as well as false, {}, or [/rx/]; anything goes except nothing.


proof is easy, just use set of negatives to test your hypothesis:

Code:
var max=Math.max.apply.bind(Math.max, 0);
var myMax= max([-4,-7,-2,-55,-2,-12]) ;

alert( myMax ); // shows "-2"
-2 is the largest numeral in the set, so this code immediately falsifies your hypothesis that the use of "0 as the second parameter in the bind for Math.max.apply ... eliminate(s) the possibility of the maximum being negative" (emphasis mine).

try something less confusing; using garbage for this, and a different apply:

Code:
var max=isNaN.apply.bind(Math.max, {a:1});
var myMax= max([-4,-7,-2,-55,-2,-12]) ;

alert( myMax ); // shows "-2"
still works. if a function doesn't use this, as Math.max doesn't, this doesn't matter.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%

Last edited by rnd me; 11-21-2012 at 09:17 AM..
rnd me is offline   Reply With Quote