首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何根据对象值返回布尔值?

如何根据对象值返回布尔值?
EN

Stack Overflow用户
提问于 2019-05-23 03:31:06
回答 3查看 105关注 0票数 0

如果对象rejectMessage包含我在checkErrorCodes方法中指定的代码,则尝试返回布尔值。它应该返回true,如果settlementCode匹配不返回的布尔值,则返回整个isError函数。有什么想法或更好的方法来完成这件事吗?

transformPrice.js

代码语言:javascript
运行
复制
function transformPrice(oldDrugPrice) {
      let drugPrice =  {
            "drugName": "Metformin",
            "mailPrice": {
                "copayEmployer": "N/A",
                "totalQuantity": "90.0",
                "rejectMessage": [{
                    "settlementCode": "99",
                    "settlementDesc": "Not Covered: Call us - System could not process your request. Call us at the toll-free number on your benefit ID card.||Sin cobertura: Llámenos - El sistema no pudo procesar su solicitud. Llame al número gratuito que figura en su tarjeta de identificación de beneficios."
                }]
            },
            "retailPrice": {
                "copayEmployer": "N/A",
                "totalQuantity": "30.0"
            }
        },

      if (drugPrice.retailPrice.rejectMessage || drugPrice.mailPrice.rejectMessage.length ){
        const retailRejecrMsg = drugPrice.retailPrice.rejectMessage;
        const mailPriceMsg = drugPrice.mailPrice.rejectMessage;
         const retailErr = isErrorPresent(retailRejecrMsg);
         const mailErr =isErrorPresent(mailPriceMsg);

      }

      return drugPrice;
    }

isErrorPresent方法

代码语言:javascript
运行
复制
function isErrorPresent (price) {
  const isError = function (element) {
    const bRet = checkErrorCodes(element);
    return (element.hasOwnProperty('settlementCode') && bRet)
  }

  return isError;
}

checkErrorCodes方法

代码语言:javascript
运行
复制
function checkErrorCodes(el){
  let bRet = false;
  const errorCodes = [
    10015,
    2356,
    225,
    224,
      99
  ]

  for (const err of errorCodes){

    if (err === el.settlementCode){

      bRet = true;
    }
  }
   return bRet;
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56263728

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档