Skip to main content
  1. About
  2. For Teams
Copy edited.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 110
  • 134

Readability should be the goal. Someone who reads the code must understand your intent immediatellyimmediately. So here is my solution.

int howManyBooleansAreTrue = 
      (a ? 1 : 0) 
    + (b ? 1 : 0) 
    + (c ? 1 : 0);

return howManyBooleansAreTrue >= 2;

Readability should be the goal. Someone who reads the code must understand your intent immediatelly. So here is my solution.

int howManyBooleansAreTrue = 
    (a ? 1 : 0) 
  + (b ? 1 : 0) 
  + (c ? 1 : 0);

return howManyBooleansAreTrue >= 2;

Readability should be the goal. Someone who reads the code must understand your intent immediately. So here is my solution.

int howManyBooleansAreTrue =
      (a ? 1 : 0)
    + (b ? 1 : 0)
    + (c ? 1 : 0);

return howManyBooleansAreTrue >= 2;
Post Made Community Wiki
Source Link
danatel
  • 5k
  • 13
  • 53
  • 66

Readability should be the goal. Someone who reads the code must understand your intent immediatelly. So here is my solution.

int howManyBooleansAreTrue = 
    (a ? 1 : 0) 
  + (b ? 1 : 0) 
  + (c ? 1 : 0);

return howManyBooleansAreTrue >= 2;
Morty Proxy This is a proxified and sanitized view of the page, visit original site.