Last active
April 15, 2016 15:31
-
-
Save cleure/7fdd4d672f1f0f53a845f1fd29788346 to your computer and use it in GitHub Desktop.
Finds the min/max range for where outliers would fall, given an array of unsorted numbers.
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
'use strict'; | |
module.exports = findOutliers; | |
/** | |
* Finds the min/max ranges for outliers, given an array of unsorted numbers. | |
* @param {Array} data | |
* @returns {Object} | |
*/ | |
function findOutliers(data) { | |
var sorted = data.sort(function (a, b) { | |
return a - b; | |
}); | |
var median = sorted[Math.floor(sorted.length * 0.5)]; | |
var q1 = sorted[Math.floor(sorted.length * 0.25)]; | |
var q3 = sorted[Math.floor(sorted.length * 0.75)]; | |
var iqr15 = (q3 - q1) * 1.5; | |
return { | |
min: q1 - iqr15, | |
max: q3 + iqr15 | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment