Open jabrena opened 7 years ago
It is very common to receive values from sensors with weird values in some cases. In order to avoid this case, it is better if the developer read the sensor some times and later calculate the median of the value.
https://en.wikipedia.org/wiki/Median
function median(values) { values.sort( function(a,b) {return a - b;} ); var half = Math.floor(values.length/2); if(values.length % 2) return values[half]; else return (values[half-1] + values[half]) / 2.0; } var list1 = [3, 8, 9, 1, 5, 7, 9, 21]; median(list1);
It is very common to receive values from sensors with weird values in some cases. In order to avoid this case, it is better if the developer read the sensor some times and later calculate the median of the value.
https://en.wikipedia.org/wiki/Median