Conditional AND statement- which is more readable? Does this function


automationStatusIsSuccessful = (data) -&gt;
    data.Automation.Status isnt "FAILED" and data.Automation.Status isnt "COMPLETEDWITHERROR"` 



make the conditional statement more readable or less readable?



With:

  automationStatusIsSuccessful = (data) -&gt;
    data.Automation.Status isnt "FAILED" and data.Automation.Status isnt "COMPLETEDWITHERROR"

  checkIteration = (data) -&gt;
    if iteration &lt; Configuration.CHECK_ITERATIONS and automationStatusIsSuccessful(data)


Without:

checkIteration = (data) -&gt;
  if iteration &lt; Configuration.CHECK_ITERATIONS and data.Automation.Status isnt "FAILED" \
  and data.Automation.Status isnt "COMPLETEDWITHERROR"
I don't know coffeescript, but in general, extracting complex conditions to a helper function is a common refactoring technique. When you do that, you effectively give a name to the previously nameless condition, which works like documentation, and can naturally improve readability.

Another advantage is that such function would hide the details of the inner workings of determining whether the automation status was successful or not. So if later you want to change the underlying conditions, the place to do that will be well identified, in a dedicated function, rather than buried inside some other function.

Of course, this doesn't mean that you should extract every less-than-trivial boolean condition to a helper function. Where you draw the line may be different from person to person. The fact that you're asking this question seems to suggest that you're inclined to make this move. (Personally I would extract it too.)