github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/pages/math.ts (about) 1 export function calculateTotal(arr: number[]) { 2 return arr.reduce((acc, b) => acc + b, 0); 3 } 4 5 export function calculateMean(arr: number[]) { 6 return calculateTotal(arr) / arr.length; 7 } 8 9 export function calculateStdDeviation(array: number[], mean: number) { 10 const stdDeviation = Math.sqrt( 11 array.reduce((acc, b) => { 12 const dev = b - mean; 13 14 return acc + dev ** 2; 15 }, 0) / array.length 16 ); 17 18 return stdDeviation; 19 }