3 ms·
median = size % 2 == 0 ? (homework[mid] + homework[mid-1]) / 2 : homework[mid]; In my opinion the ternary operator is misused here when an if/else would have b
by kupo 13y ago
median = size % 2 == 0 ? (homework[mid] + homework[mid-1]) / 2 : homework[mid];
In my opinion the ternary operator is misused here when an if/else would have been clearer.
- city41 13y agoAh yeah, that is one beefy line of code. I can agree with that.
- banachtarski 13y agoWell, you omitted the all important const qualifier which would be a decent reason to use the ternary operator.
- ufo 13y agoI actually like using the ternary operator in this sort of assignment, so I only need to type the variable name once instead of 3 times. The only real problem in your example is that everything is in one line. It woulf be better to indent that and to add some extra parenthesis to make the precedence clearer.