2

I have multiple records that have type and status. In case where record type is 'DEV' then the status should be checked. In that case if status is 'Y' then variable should be set to true. Here is example of few records:

RecID  Type  Status
1      PROD    N
2      PROD    N 
3      PROD    N
4      DEV     Y
5      TEST    N

I have developed logic that works, here is example:

var showRec = false;

if (type === 'DEV') {
   if(status === 'Y') {
      showRec = true;
   }
}else{
   showRec = true;
}

Then I'm able to use showRec variable to show hide the elements. I'm wondering if logic above can be simplified? I couldn't find better way to approach this problem. Also I was wondering if this could be done in SQL with CASE WHEN and then simply use that column that will have Yes\No or true\false. If anyone have any suggestions please let me know.

espresso_coffee
  • 5,980
  • 11
  • 83
  • 193

2 Answers2

2

You can combine the logic this way:

const showRec = type !== 'DEV'|| status === 'Y';

This demands that either type be something other than "DEV", or if it is, then status must also be "Y".

Duncan Thacker
  • 5,073
  • 1
  • 10
  • 20
2

You could use a ternary which checks the type and takes, if true the reuslt of the other check or true.

showRec = type === 'DEV' ? status === 'Y' : true;
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392