(array: number[])
| 42 | * @returns The standard deviation of the input array. |
| 43 | */ |
| 44 | export function stdDev(array: number[]): number { |
| 45 | try { |
| 46 | const n = array.length; |
| 47 | const meanValue = mean(array); |
| 48 | return Math.sqrt( |
| 49 | array.map((x) => Math.pow(x - meanValue, 2)).reduce((a, b) => a + b) / n, |
| 50 | ); |
| 51 | } catch (e) { |
| 52 | return 0; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Calculates the median of an array of numbers. |