如何让函数变得简单

也许删除一些逻辑运算符,制作“检查功能”?


还是将一些逻辑连接在一起?


// 功能


function getTicketPrice(childNumber,adultNumber){


  if (childNumber > 2 && adultNumber > 2) {

    return "-";

  }

    if (childNumber == 2 && adultNumber == 3) {

    return "-";

  }

    if (childNumber == 3 && adultNumber == 2) {

    return "-";

  }  


  var sheet = SpreadsheetApp.openByUrl(url).getSheetByName("Ticket");  

  var row = getTicketPriceChild(childNumber, sheet);

  var col = getTicketPriceAdult(adultNumber, sheet);


    if (row >-1 && col === undefined) {

    return "-";

  }

    if (row === undefined && col >-1) {

    return "-";

  }    


  var value = sheet.getRange(row, col).getValue();


    if(value > 1){

    return value;

  } else {

    return '-';

  }

}


慕斯王
浏览 141回答 1
1回答

HUWWW

像这样的东西:function getTicketPrice(childNumber, adultNumber) {  if ((childNumber > 2 && adultNumber > 2) || (childNumber == 2 && adultNumber == 3) || (childNumber == 3 && adultNumber == 2))    return "-";  const sheet = SpreadsheetApp.openByUrl(url).getSheetByName('Ticket');  const row = getTicketPriceChild(childNumber, sheet);  const col = getTicketPriceAdult(adultNumber, sheet);  if ((row > -1 && col === undefined) || (row === undefined && col > -1))    return "-";  const value = sheet.getRange(row, col).getValue();  return value > 1 ? value : "-"}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript