Last active
November 14, 2020 21:02
-
-
Save ehzawad/e134399b5cddda8f3e0015ddb132b54c to your computer and use it in GitHub Desktop.
This file contains 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
let orders = [26, 3, 5, 7, 8, 5, 0, 8, 4] | |
let arrSum = arr => (arr.reduce((x, accumulate) => accumulate + x, 0)) | |
let avgOrders = arrSum(orders)/orders.length | |
console.log(avgOrders) | |
let differences = orders.map(x => x - avgOrders).map(x => x * x) | |
console.log(differences) | |
let variance = arrSum(differences)/differences.length // orders.length === differences.length | |
console.log(variance) | |
let standardDeviation = Math.sqrt(variance) | |
console.log(standardDeviation) | |
let isOutlier = orders.map(x => Math.abs(x - avgOrders) > standardDeviation) | |
console.log(isOutlier) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment