mercredi 25 mai 2016

How to optimize the 3 conditions if else if Statements

Hi i have to check the three conditions, is there any Way to optimize the code other than the if else if statements. if i am checking all the three combinations its going to more lines of code do we have any better option to check all the conditions. Please can anybody help me on this to optimize the code.

if (req.body.officeId === "null" && req.body.branchId === "null" && req.body.productId === "null") {
  updatedTestData = _.omit(req.body, ['officeId', 'branchId', 'roomId']);
  updatedTestData.officeId = null;
  updatedTestData.office = {};
  updatedTestData.branchId = null;
  updatedTestData.branch = {};
  updatedTestData.productId = null;
  updatedTestData.product = {};

} else if (req.body.officeId === "null" && req.body.branchId === "null" && !req.body.productId === "null") {
  updatedTestData = _.omit(req.body, ['officeId', 'branchId']);
  updatedTestData.officeId = null;
  updatedTestData.office = {};
  updatedTestData.branchId = null;
  updatedTestData.branch = {};

}

Aucun commentaire:

Enregistrer un commentaire