我已经成功优化了一些只需1个输入范围的google脚本功能。
我试图将1个数组(名称)和2个值(日期和学校名称)或3个数组作为输入。
这就是代码:
// input - array of names like this 'Jon Snow'
// date - date with format like this '2017-12-28'
// school name like this 'School name'
function Allanswers(input, date, school) {
if (input.map) { // Test whether input is an array.
return input.map(function(x, date, school){ // Recurse over array if so.
return Allanswers(x, date, school)
});
} else {
return date; // returns 0
// the function is much more complicated but with this line I am checking if the value of date is taken from google spreadsheet
}
}
答案 0 :(得分:0)
问题是我对.map
了解不多我已经阅读了一些关于谷歌脚本非常好的书的部分内容" Going GAS"。
我的问题的答案是:
// this function can be used with vertical input array and horizontal date and school arrays or values
function Allanswers(input, date, school ) {
if ( !Array.isArray(date) ) {
return input.map (function (d, i) {
return process (d[0], date, school)
})
}
else {
return input.map (function (d, i) {
return date[0].map (function (k, h) {
return process (d[0], k, school[0][h])
})
})
}
function process(teacher, day, place) {
// your calculations
}
}