Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

avg.as

Name: Math.avg(); returns average of any number of arguments
Author: senocular: www.senocular.com
Date: 
1899-12-31T00:55:25.400
Documentation:
Math.AVG: returns a numerical average of passed arguments

Arguments:
- any number of comma seperated Number values to be averaged

Returns:
- The average of the specified arguments.  If no arguments are passed, a null is returned.

Example:
trace(Math.avg(1,2,3)); // traces 2

1
2
3
4
5
6
7
8
Math.avg = function(){
	var i=arguments.length;
	if (i){
		var j=i, sum=0;
		while(i--) sum+=arguments[i];
		return sum/j;
	}else return null;
}