Quick question about refactoring a ternary, how would I remove the ternary from this if I want to get rid of function1?
return !test1 && test2 ? function1() : function2();
I tried:
if(!test1 && test2) {
return function2();
}
The program I’m working on has linting set up and is yelling at me that theres no return… did I refactor it wrong? What would be the best way to refactor it?
Summary
This text will be hidden
return today === friday ? "TGIF" : "despair";
This is the same as above
if (today === friday) {
return "TGIF";
}
return "despair";
if the condition on the left of the ternary is correct it returns function1(), but your if statement uses the same condition to return function2() ?
shouldn’t the condition be if (test1 && !test2)
?
test1 && !test2
is not the negation of !test1 && test2
.
system
Closed
March 26, 2022, 6:46am
6
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.