Skip to content

patgarcia/standard-deviation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

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 }
}

About

Simple standard deviation function

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published