I think your own suggestion is a good start. You can reduce it a little bit -- no need for the first var
:
if (selectedNonTarget(that.selected, target))
{
// continue above code;
}
function selectedNonTarget(selected, target){
// return a bool -- resist the urge to do other things here
return (selected && selected != target);
}
This is good coding practice to reduce a compound condition to a well-named function and then treat it like a simple true | false in your main logic. This should help reduce the cognitive load as your code base grows -- and every little bit helps.
Sure we all understand what &&
and !=
are supposed to mean and do but at 2am after 12 hours of coding, you'll be less error-prone with if (selectedNonTarget(that.selected, target))
I would also strongly recommend spending some time splitting the 1000 or so lines of code you have into multiple files. You will find this worthwhile.