import { AccessorT , Observer , Accessor } from "./observer" ; function _variance ( ) { let count ; let mean ; let sum ; return { observe : ( value , idx ) => { if ( idx === 0 ) { count = 0 ; mean = 0 ; sum = 0 ; } const delta = value - mean ; mean += delta / ++ count ; sum += delta * ( value - mean ) ; } , peek : ( ) => count > 1 ? sum / ( count - 1 ) : undefined } ; } export type VarianceAccessor < T > = AccessorT < T , number > ; export function variance ( ) ; export function variance < T = any > ( callbackFn ) ; export function variance < T = any > ( callbackFn ? ) { return callbackFn ? Accessor ( _variance , callbackFn ) : _variance ( ) ; }