Skip to content

Instantly share code, notes, and snippets.

@cleure
Last active April 15, 2016 15:31
Show Gist options
  • Save cleure/7fdd4d672f1f0f53a845f1fd29788346 to your computer and use it in GitHub Desktop.
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.
'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