How can I add my functions to the arrays namespace?
I created functions in an extension and placed them in the arrays namespace. But they don’t show up in the toolbox’s arrays section. I tried placing them in subcategory, but nothing happens. Is there a way to solve this?
namespace arrays {
/**
\* Поиск наиболее часто встречающегося числа в массиве - мода.
\* Если массив был пустым, то вернёт null.
\* @param numbers массив с числами
\*/
//% blockId="Mode"
//% block="mode of $numbers array"
//% weight="89"
//% blockNamespace="custom"
//% subcategory="Ext"
//% group="Statistics"
export function mode(numbers: number\[\]): number {
if (numbers.length === 0) return null;
numbers.sort((a, b) => a - b);
let maxCount = 0, currentCount = 1;
let currentNum = numbers\[0\], mostFrequentNum = numbers\[0\];
for (let i = 1; i < numbers.length; i++) {
if (numbers\[i\] === currentNum) currentCount++;
else {
if (currentCount > maxCount) {
maxCount = currentCount;
mostFrequentNum = currentNum;
}
currentNum = numbers\[i\];
currentCount = 1;
}
}
if (currentCount > maxCount) mostFrequentNum = currentNum;
return mostFrequentNum;
}
}