description author shawn8901 example export class Average { public static calculate ( periods , length , source = 'close' ) { const values = periods . slice ( 0 , length ) . filter ( ( v ) => typeof v [ source ] === 'number' ) . map ( ( v ) => v [ source ] ) ; return this . calculateValue ( values , length ) ; } public static calculateValue ( values , length ) { if ( values . length < length ) return null ; return values . reduce ( ( sum , value ) => sum + value ) / length ; } }