Created
April 10, 2017 18:16
-
-
Save robertscherbarth/a97456217e3ab55da66471532cf7262c to your computer and use it in GitHub Desktop.
Standard deviation order example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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