Skip to content

Instantly share code, notes, and snippets.

@robertscherbarth
Created April 10, 2017 18:16
Show Gist options
  • Save robertscherbarth/a97456217e3ab55da66471532cf7262c to your computer and use it in GitHub Desktop.
Save robertscherbarth/a97456217e3ab55da66471532cf7262c to your computer and use it in GitHub Desktop.
Standard deviation order example
/* Standard Deviation */
const orders = [3, 5, 3, 8, 5, 25, 8, 4]
const arrayAverage = arr => arr.reduce((sum, x) => x + sum, 0) / orders.length
const sumOrders = orders.reduce((sum, x) => x + sum, 0)
const averageOrders = arrayAverage(orders)
console.log(averageOrders)
const differences =
orders.map(x => x - averageOrders).map(x => x * x)
console.log(differences)
const averageDifference = arrayAverage(differences)
console.log(averageDifference)
const standardDeviation = Math.sqrt(averageDifference)
console.log(standardDeviation)
const isOutlier = orders.map( x => x - averageOrders - standardDeviation > 0)
console.log(isOutlier)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment