Skip to content

Instantly share code, notes, and snippets.

@jonathanmarvens
Last active May 8, 2018 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanmarvens/d8421f3769f880aa4af3baf978a8e8fc to your computer and use it in GitHub Desktop.
Save jonathanmarvens/d8421f3769f880aa4af3baf978a8e8fc to your computer and use it in GitHub Desktop.
const mean = (values) => {
const sum = values.reduce((sum, value) => (sum + value), 0)
const valuesCount = values.length
return (sum / valuesCount)
}
const standardDeviation = (values) => {
const average = mean(values)
const squaredDifferences = values.map((value) => {
const difference = (value - average)
return (difference * difference)
})
const squaredDifferencesAverage = mean(squaredDifferences)
return Math.sqrt(squaredDifferencesAverage)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment