E: me@sabisin.com | T: +49.151.68651209

Minimum or Maximum value from an array of numbers

First, note that Math.min() and Math.max() can take any number of arguments. Also, it’s important to understand the apply() method available to Function objects. It allows you to pass arguments to the function using an Array. Let’s take advantage of both:

var aRr:Array = [2,3,3,4,2,2,5,6,7,2];
var mAxvAlue:Number = Math.max.apply(null, aRr);
var mInvAlue:Number = Math.min.apply(null, aRr);

Here’s the best part: the “loop” is actually run using native code (inside Flash Player), so it’s faster than searching for the minimum or maximum value using a pure ActionScript loop.