The ternary operator isn't a substitute for
if
...
else
, or even a shorthand for it - though under some circumstances it can be used that way.
For example, this code:
if (a > b)
c = a;
else
c = b;
Can be shortened using a ternary operator to this:
c = a > b ? a : b
Because both the
if
and
else
blocks have one job: setting the value of the same variable.
Your code doesn't do that: it does "extra" things like setting the value of
histarr.count
.
While it could be possible to mangle that code into a couple of nested ternary operators using a bunch of subroutines, the resulting code would be almost unreadable, and would be very hard to both debug and modify.
Just because you can do something, doesn't mean you should!