Simplify nested if/else with repeated results?
function handleDirection(src) {
var movement = 1;
if(src === 'left')
movement = -1;
if(inverse)
tracker += movement;
else
tracker -= movement;
}
You could check with the result of the first check.
This is an exclusive OR check.
// typeof inverse === 'boolean'
function handleDirection(src) {
if (src === 'left' === inverse) {
tracker--;
} else {
tracker++;
}
}
The check evaluates the expression in this order (src === 'left') === inverse
:
src === 'left' === inverse
---- first --- returns a boolean value
--------- second --------- take result of former check & compairs it with another boolean