From 7567d9f532f0abd59e2fecfcbcf496f1c309fdf4 Mon Sep 17 00:00:00 2001 From: andowinger <45272122+andowinger@users.noreply.github.com> Date: Sun, 27 Mar 2022 23:49:26 +0200 Subject: [PATCH] Update 17-smooth.js --- function/smooth/17-smooth.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/function/smooth/17-smooth.js b/function/smooth/17-smooth.js index 67594606..9545051b 100644 --- a/function/smooth/17-smooth.js +++ b/function/smooth/17-smooth.js @@ -55,14 +55,15 @@ module.exports = function(RED) { 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] + var sortedForMedian = v[top].a.slice().sort((a, b) => a - b); + var medianIndex = Math.floor(v[top].iter / 2); + if (v[top].iter % 2 === 0) { + value = (sortedForMedian[medianIndex - 1] + sortedForMedian[medianIndex]) / 2; } + else { + value = sortedForMedian[medianIndex] + } + } if (node.action === "sd") { v[top].tot = v[top].tot + n - v[top].pop;