Contact
| ABN 76 112 803 072
Folio currently contains
131
items
Products
SeniorStore e-shop
SeniorCMS content management
Digital Signage
Flash & AIR
Video + Broadcast Apps
AIR Apps
Flash Apps / Sites
AS3 Code
Games
Animations
E-cards
Websites
Flash Sites
Dynamic PHP Sites
E-Commerce Sites
Photography Sites
iPhone/iPad Friendly Sites
Games
Flash Games
Shockwave Games (Old)
Competitions
Animation
Flash Animations
Banners
E-cards
DVD Menus
DVD Showreels
Design
DVD Menus
DVD Showreels
Graphics
Experimental
Code
Recent Work
Top Ten Views This Month
Contact us
Viewed
19
times this month
Actionscript 3.0 - LEVEL
INTERMEDIATE
AS3 Calculate Median Value
Last edited 14TH DEC, 2010
Pass in an array of numeric values in any order and it will return you the median value which is the middle value for an odd length of values, or the mid-point between the two middle numbers for an even length of values
public static function calculateMedian(_values:Array) : Number { var median:Number; var middleIndex:int; _values.sort(Array.NUMERIC); if (_values.length % 2 == 0) { // even length of values list middleIndex = Math.round((_values.length / 2)); median = _values[middleIndex-1] + ((_values[middleIndex] - _values[middleIndex-1])/2); } else { // odd length of values list - get middle value - thats the median... middleIndex = Math.round((_values.length / 2)); median = _values[middleIndex-1]; } return median; }