I am refactoring a switch statement in which I am performing am if
conditional within one of the cases where the if
will break
the switch case and the else
will return
.
Is it possible to perform this as a quicker conditional such as a Ternary or something else, rather than a standard if/else?
Original
let someCondition;
// someCondition is set at some point
switch(toSwitchOn) {
case myCase:
if (someCondition) {
sendObj({someKey: 'someVal', condition: true});
break;
} else {
sendObj({condition: false});
return false;
}
}
Refactored so far
let someCondition;
// someCondition is set at some point
switch(toSwitchOn) {
case myCase:
sendObj({
...!!someCondition && {someKey: 'someVal'},
condition: !!someCondition
});
if (someCondition) { break; } else {return false}
}