Skip to content

Instantly share code, notes, and snippets.

@think2011
Last active February 5, 2016 14:37
Show Gist options
  • Save think2011/67d95a1ab09173eba05e to your computer and use it in GitHub Desktop.
Save think2011/67d95a1ab09173eba05e to your computer and use it in GitHub Desktop.
根据rangeNum筛选有效数得出平均值
/**
* 根据 rangeNum 过滤掉超出的平均值的数值
* @param arr
* @param rangeNum
* @returns Array
*/
function clearMean (arr, rangeNum) {
arr = arr.concat().sort();
var middleNum = arr[Math.ceil(arr.length / 2)];
return arr.filter(v => {
if (middleNum > v) {
return middleNum - v < rangeNum;
} else {
return v - middleNum < rangeNum;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment