Is there a simple heuristic for understanding how to read nested ternary operators? I came across this in someone's source code and can't grok it. A simple ternary is easy:
isRed = color == 'red' ? true : false
But how do you read the following? Can I just line up the first with the last and the second with the second to last, or must I parse this into an if/else tree in my head?
var offset =
( hasFrozenRows )
? ( options.frozenBottom )
? ( row >= actualFrozenRow )
? ( h < viewportTopH )
? ( actualFrozenRow * options.rowHeight )
: h
: 0
: ( row >= actualFrozenRow )
? frozenRowsHeight
: 0
: 0;
Retabbed, it can look like this, which is almost understandable (?)
var offset =
( hasFrozenRows ) ?
( options frozenBottom ) ?
( row >= actualFrozenRow ) ?
( h < viewportTopH ) ?
( actualFrozenRow * options.rowHeight )
:
h
:
0
:
( row >= actualFrozenRow ) ?
frozenRowsHeight
:
0
:
0;