Posted 14 June 2023, 11:57 pm EST
Hello,
You can override the acceptsReference() method of the function. This method takes argument index and returns true or false for whether the function argument accepts references or not. If it returns true for an argument, then instead of value, a reference is passed in the evaluate() method of the function.
You can use toArray() method on the reference of argument to get the value array and according implement your logic.
Please refer to the code snippet and attached sample for more understaning.
function CustomFunction() {
this.name = 'CUSTOMFUNC';
this.minArgs = 1;
this.maxArgs = 255;
}
CustomFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
CustomFunction.prototype.evaluate = function () {
// your own evaluate content
let minValue = Number.MAX_SAFE_INTEGER;
for (let arg of arguments) {
if (arg.toArray) {
arg.toArray().forEach((val) => {
if (val < minValue) {
minValue = val;
}
});
} else if (Number.isInteger(arg) && minValue > arg) {
minValue = arg;
}
}
return 2 * minValue;
}
CustomFunction.prototype.acceptsReference = function (index) {
return true;
}
// r
eturns the description for the function
CustomFunction.prototype.description = function (arg1, arg2) {
return {
description: “Returns the double of the minimum of the two values”,
};
}
nction.evaluate():
https://www.grapecity.com/spreadjs/api/classes/GC.Spread.CalcEngine.Functions.Function#evaluate
regards,
Avinash