@cran/lib.vue.ref
Version:
Vue Reactivity Extensions
23 lines (18 loc) • 451 B
text/typescript
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;
});
}