Google 多于1个输入值的脚本函数优化

Google script function optimization with more than 1 input value

我已经成功地优化了一些只需要 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
  }
  }

问题是我对 .map 了解不多

我读了一些关于 google 脚本的好书 "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
}
}