1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Update 17-smooth.js

This commit is contained in:
andowinger 2022-03-27 22:56:10 +02:00 committed by GitHub
parent 4508c3f67b
commit 262976efc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,6 +54,16 @@ module.exports = function(RED) {
v[top].tot = v[top].tot + n - v[top].pop;
value = v[top].tot / v[top].a.length;
}
if (node.action === "median") {
var sortedForMedian = v[top].a.slice().sort((a, b) => a - b);
var medianIndex = Math.floor(v[top].count / 2);
if (v[top].count % 2 === 0) {
value = (v[top].sortedForMedian[v[top].medianIndex - 1] + v[top].sortedForMedian[v[top].medianIndex]) / 2;
}
else {
value = v[top].sortedForMedian[v[top].medianIndex]
}
if (node.action === "sd") {
v[top].tot = v[top].tot + n - v[top].pop;
v[top].tot2 = v[top].tot2 + (n*n) - (v[top].pop * v[top].pop);