Hi! I’ve encountered a bug when using the median Operator (TW v5.3.6):
Filter: =1 =300 =4 =5 +[median[]]
Output: 152
Expected output: 4.5
The values are sorted as strings as opposed to numbers in $:/core/modules/filters/math.js:
exports.median = makeNumericArrayOperator(
function(values) {
var len = values.length, median;
values.sort();
I changed it to values.sort( (a, b) => a-b );
in an empty file and the filter returned the correct output.
Array.prototype.sort() - JavaScript | MDN :
To memorize this, remember that
(a, b) => a - b
sorts numbers in ascending order.If omitted, the array elements are converted to strings, then sorted according to each character’s Unicode code point value.