variance function

double variance(
  1. Array a
)

Return the variance of the array

Examples

var n = Array([1, 2, 3]);

print(variance(n));

Implementation

double variance(Array a) {
  var meanA = mean(a);
  var temp = 0.0;
  for (var el in a) {
    temp += (el - meanA) * (el - meanA);
  }
  return temp / (a.length - 1);
}