title: if undefined or empty or indexOf match then
body: <p>I have a javascript function where an option can get passed in. The option is for specifying a restriction, and thus if the option is undefined, null, or an empty array then no restriction applies and all data rows get tested. If an array of options is provided, then only the data rows matching one of the restrictions gets whacked.</p>
  
  <p>That is, the function needs to test every element of a data array and then also optionally do a check against the restriction option if a restriction option has been provided.</p>
  
  <p><strong>Is there a shorter way to write the test?</strong></p>
  
  <pre><code>function dostuff (data, option) {
    for (var i = 0; i &lt; data.length; i++) {
      if ((test(data[i].x) &amp;&amp; !option) ||
          (test(data[i].x) &amp;&amp; !option.length) ||
          (test(data[i].x) &amp;&amp; Array.isArray(option) &amp;&amp; option.length &amp;&amp; option.indexOf(data[i].y) != -1)
         ) // ZOMG! Can this be shorter?
      {
        // do stuff
      }
    }
  }
  </code></pre>
  
  <hr>
  
  <p>ps. I'm not after some impossible to read chunk of code golf black magic. Just something that's shorter and succinct and sensible.</p>