mirror of
https://github.com/photonstorm/phaser
synced 2024-12-25 04:23:30 +00:00
29 lines
611 B
JavaScript
29 lines
611 B
JavaScript
/**
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
* @copyright 2019 Photon Storm Ltd.
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
*/
|
|
|
|
/**
|
|
* Calculate the mean average of the given values.
|
|
*
|
|
* @function Phaser.Math.Average
|
|
* @since 3.0.0
|
|
*
|
|
* @param {number[]} values - The values to average.
|
|
*
|
|
* @return {number} The average value.
|
|
*/
|
|
var Average = function (values)
|
|
{
|
|
var sum = 0;
|
|
|
|
for (var i = 0; i < values.length; i++)
|
|
{
|
|
sum += (+values[i]);
|
|
}
|
|
|
|
return sum / values.length;
|
|
};
|
|
|
|
module.exports = Average;
|