0

1つの入力範囲しか取らないGoogleスクリプト関数の一部を最適化するのに成功しました。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

問題は、私は「ガスを行く」Googleのスクリプトについては非常に良い本のいくつかの部分を読んでいるの.map

についてあまり知らなかったということでした。

そして、私の質問への答えは、このでした:

// 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 
} 
} 
関連する問題