EDIT Thanks for reopening - I have redrafted the question to make it (hopefully) a bit sharper. /EDIT
I wrote an Apps Script function "remainingDigits" (see below). As input parameters, the function takes 0-10 digits in the form (n,n,..,n) where 0<=n<9.
The purpose of the function is to calculate which digits in the range 0-9 were NOT passed as input parameters e.g. if the inputs were 6, 7, 2 & 4 then the result should be 0, 1, 3, 5, 8 & 9.
The function treats the inputs as an array of values and on completion returns an array of values.
Using a very simple test harness (see below), if executed entirely within Apps Scripts, this works perfectly.
However, when called from a cell in Sheets, it exhibits what is (to me at least) rather bizarre behaviour, as follows:
Cell Values (for all tests) : A7=6, A8=7, A9=2, A10=4
Test 1
Calling cell function "=remainingDigits(A7, A8, A9, A10)"
Response in Sheets Error message
"TypeError: digits.indexOf is not a function (line 20)"
Test 2
Calling cell function "=remainingDigits({A7, A8, A9, A10})"
Response in Sheets Value of the calling cell is set to 0, and the value of the 9 cells beneath it are set to 1,2,3 .... 9
Test 3
Calling cell function "=remainingDigits(A7:A10)"
Response in Sheets Same as Test 1
Test 4
Calling cell function "=remainingDigits({A7:A10})"
Response in Sheets Same as Tests 3
All very strange !
Any tips for fixing this would be much appreciated :)
Here's the code:
function testRD() {
// A simple test harness for remainingDigits function
let results = new Array;
results = remainingDigits([0,1,2,3,4]);
var a;
for(a=0;a<=results.length-1;a++){
Logger.log(results[a]);
}
}
function remainingDigits(digits){
let remDigits = new Array;
var d;
for(d=0;d<=9;d++){
if(digits.indexOf(d)!=-1){
}
else {
remDigits.push(d);
}
}
return remDigits;
}