I have a piece of code:
if (foo > bar) {
baz = foo - bar
} else {
baz = foo + bar
}
I have a question if I can somehow shorten this code to a single line, something like
PSEUDOCODE:
baz = foo (foo > bar ? + : -) bar
Real code I'd like to shorten
if (gradientStartH > gradientEndH) {
h = gradientStartH - Math.abs(gradientStartH - gradientEndH) / arr.length * i
} else {
h = gradientStartH + Math.abs(gradientStartH - gradientEndH) / arr.length * i
}
Thanks!
baz = (foo > bar) ? (foo - bar) : (foo + bar)
? – Nuzzi