movingAverage method

List<double> movingAverage(
  1. int samplesSize
)

Implementation

List<double> movingAverage(int samplesSize) {
  var length = this.length;
  if (samplesSize >= length) return <double>[mean];

  var movingAverage = <double>[];
  for (var i = 0; i < length; ++i) {
    var end = i + samplesSize;
    if (end > length) break;

    var total = 0.0;
    for (var j = i; j < end; ++j) {
      var e = this[j];
      total += e;
    }

    var average = total / samplesSize;
    movingAverage.add(average);
  }

  return movingAverage;
}