I've writen the following code to implement a custom Google Spreadsheet function; the goal is to write all possible games between teams whose names are listed in 'names' parameter:
function ALLGAMES( names )
{
var nbTeams = names.length;
var gameList = [];
for( var t1=0; t1<nbTeams-1; t1++ ) {
for( var t2=t1+1; t2<nbTeams; t2++ ) {
gameList.push( [ new String(names[t1]), new String(names[t2]) ] );
//A. gameList.push( [ t1, t2 ] );
}
}
// B. return JSON.stringify(gameList)
// C. return [[ 'a', 'b' ], ['c', 'd']]; //using the value returned by JSON.stringify
return gameList;
}
When I use the function in the spreadsheet, it fills cells with blank values instead of the teams names.
However, the behaviour is as expected in any of the following cases:
- If I use the A. line (pushing numbers instead of strings), it displays all the numbers correctly
- If I use the B. line (returning the JSON string for the array), it displays a correct JSON string
- If I use the C. line (returning the array in full), it works as expected.
Where is the problem?
Edit 1: