UNPKG

@cran/lib.vue.ref

Version:

Vue Reactivity Extensions

23 lines (18 loc) 451 B
import { computed } from "vue"; import { type MaybeWrapped, unwrap } from "../utility"; /** * @since 0.0.1 * @category Statistics */ export function useStatAvg ( values: MaybeWrapped<Array<MaybeWrapped<number>>> ) { return computed(function computedMathAvg ( ) { let result = 0; let index = 0; for (const value of unwrap(values)) { result = (( index * result ) + unwrap(value)) / ++index; } return result; }); }