Skip to content

Instantly share code, notes, and snippets.

@icodeforlove
Created June 14, 2012 22:26
Show Gist options
  • Save icodeforlove/2933401 to your computer and use it in GitHub Desktop.
Save icodeforlove/2933401 to your computer and use it in GitHub Desktop.
function RollingAverage ($config) {
$config = $config || {};
this._average = $config.average || 0;
this._numbers = $config.numbers || 0;
}
RollingAverage.prototype.push = function (number) {
this._numbers++;
var weight = 1 / this._numbers;
this._average += (number - this._average) * weight;
return this._average;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment