export function sum ( arr ) { let sum = 0 ; let i = arr . length ; while ( i > 0 ) { sum += arr [ -- i ] ; } return sum ; } export const percentChange = ( current , prev ) => ( ( current - prev ) / prev ) * 100 ; export const avg = ( arr , period = arr . length ) => sum ( arr ) / period || 0 ; export const getMax = ( arr ) => { let max = - Infinity ; let idx = 0 ; for ( let i = arr . length - 1 ; i >= 0 ; i -- ) { const item = arr [ i ] ; if ( max < item ) { idx = i ; max = item ; } } return { max , idx } ; } ; export const getMin = ( arr ) => { let min = Infinity ; let idx = 0 ; for ( let i = arr . length - 1 ; i >= 0 ; i -- ) { const item = arr [ i ] ; if ( min > item ) { idx = i ; min = item ; } } return { min , idx } ; } ;