Issue
I have the following if
statement. Is this expression able to be simplified into a ternary statement? I'm having trouble figuring it out since group
needs to be assigned based on the value of coverageLineId
let group;
if(coverageLineId == 1)
group = this.medicalBenefitsGroupsView.find((x) => x.value === groupValue);
else if (coverageLineId == 2)
group = this.dentalBenefitsGroupsView.find((x) => x.value === groupValue);
else if (coverageLineId == 3)
group = this.visionBenefitsGroupsView.find((x) => x.value === groupValue);
Solution
If you really want to make it more concise, you can do this:
let group = this[["", "medical", "dental", "vision"][coverageLineId] + "BenefitsGroupsView"].find((x) => x.value === groupValue);
However, I think I'd do this:
let view;
switch (coverageLineId) {
case 1:
view = this.medicalBenefitsGroupsView; break;
case 2:
view = this.dentalBenefitsGroupsView; break;
case 3:
view = this.visionBenefitsGroupsView; break;
}
let group = view.find((x) => x.value === groupValue);
Answered By - pigrammer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.