function multiMax(multi){
// Make an array of all but the first argument
var allButFirst = Array().slice.call( arguments, 1 );
// Find the largest number in that array of arguments
var largestAllButFirst = Math.max.apply( Math, allButFirst );
// Return the multiplied result
return multi * largestAllButFirst;
}
assert( multiMax(3, 1, 2, 3) == 9, "3*3=9 (First arg, by largest.)" );
from http://ejohn.org/apps/learn/#47
I have two questions for anyone.
- Why do we need to use Array().slice, but not Math().max.
- Why do we use Array().slice, and not Array.prototype.slice (I noticed that Array.prototype.slice will work, but I'm trying to understand why i would use one over the other, not just in this instance, but in any instance)
Thank you.