mean

Calculates the arithmetic mean of a non-empty array with Arith decimal arithmetic.

import { Arith } from "@teakit/arith";

Arith.mean(["10", "20", "30"]).toString(); // "20"
Arith.mean(["1.1", "2.2", "3.3"]).toString(); // "2.2"

// Inputs may already be Arith instances.
Arith.mean([Arith.from("0"), "0.5", "0.5"]).toString(); // "0.33333333333333333333"

// Cloned constructors use their own precision config.
const Short = Arith.clone({ DECIMAL_PLACES: 4 });
Short.mean(["0", "0.5", "0.5"]).toString(); // "0.3333"

API Reference

Signature

Arith.mean(values: readonly ArithValue[]): ArithInstance;

Parameters

ParameterTypeRequiredNotes
valuesreadonly ArithValue[]YesNon-empty array of finite values.

Returns

Returns a new Arith instance containing sum(values) / values.length.

Throws

  • Throws if values is not a non-empty array.
  • Throws if any value is NaN, Infinity, or -Infinity.

Agent Contract

FieldValue
Kindstatic method
Canonical namemean
AliasesNone
Mutates receiverNo
ReturnsArithInstance
Accepts (string, base) overloadNo
Configuration dependenciesDECIMAL_PLACES, ROUNDING_MODE, STRICT
Related methodssum, weightedMean

Agent Notes

  • Use Arith.mean(values), not JavaScript Array.reduce with +, for decimal arrays.
  • Use string inputs for exact decimal values.
  • Do not generate average; it is not a public alias.