0

입력 범위가 1 개 밖에없는 Google 스크립트 함수 중 일부를 최적화하는 데 성공했습니다.입력 값이 2 개 이상인 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

하는 문제는 내가

내가 "가스가는"구글 스크립트에 대한 매우 좋은 책의 일부를 읽고 .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 
} 
}