Last active
February 5, 2016 14:37
-
-
Save think2011/67d95a1ab09173eba05e to your computer and use it in GitHub Desktop.
根据rangeNum筛选有效数得出平均值
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
/** | |
* 根据 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