mercredi 3 juillet 2019

How to check if value exist and return boolean?

those specific properties contain N/A or n/a function validateValues should return true otherwise it should return false, in below code it always return true any idea what is implemented wrong here ?

main.js

const price = {
copayEmployer: "N/A",
costAnnual: "135.60",
costEmployer: "16.95",
costEmployerAnnual: "203.40",
costToday: "11.30",
daysSupply: "5",
deductible: "0.00",
flexPayIndicator: false,
healthcareReimbursementAcctAppliedAmount: "0.00",
memberCopayAmount: "11.30",
ndcId: "43386035101",
penalties: "-0.00"
secondaryClaimNumber: "191844037055002",
secondaryClaimSequenceNumber: "999",
totalDrugCost: "28.25",
totalDrugCostAnnual: "339.00",
totalDrugCostPerUnitAnnual: "N/A",
totalQuantity: "20.0"
};

function validateValues (price) {
  let bRet = false;
  const na = ["N/A", "n/a"];

if (na.indexOf(price.costEmployer) != -1 
    || na.indexOf(price.costToday) != -1
    || na.indexOf(price.penalties) != -1
     || na.indexOf(price.deductible) != -1
     || na.indexOf(price.totalDrugCost != -1)
     || na.indexOf(price.memberCopayAmount != -1)) {

    bRet = true;
}

  return bRet;
}

console.log(validateValues(price));

Aucun commentaire:

Enregistrer un commentaire