Skip to content

Latest commit

 

History

History
18 lines (16 loc) · 516 Bytes

README.md

File metadata and controls

18 lines (16 loc) · 516 Bytes

standard-deviation

Simple standard deviation function

function std(numArray, stdOnly = true) {
    // N the size of the population
    // x each value from the population
    // μ the population mean
    // σ population standard deviation
    const N = numArray.length;
    const μ = numArray.reduce((acc, x) => acc + x) / N;
    const σ = Math.sqrt(
        numArray.reduce((acc, x) => acc + (x - μ) ** 2, 0) / N
    )

    return stdOnly ? σ : { std: σ, mean: μ, populationSize: N }
}