Skip to content

meanOrThrow

ts
function Array.meanOrThrow(target: readonly number[]): number

Returns the mean (average) value from array, or throws an error if the array is empty.

Example

ts
import { Array } from "@monstermann/array";

Array.meanOrThrow([1, 2, 3]); // 2
Array.meanOrThrow([]); // throws FnError
ts
import { Array } from "@monstermann/array";

pipe([1, 2, 3], Array.meanOrThrow()); // 2
pipe([], Array.meanOrThrow()); // throws FnError