title: how could I reduce the cyclomatic complexity?
body: <p>Whenever I lint a piece of code I'm working on I get the <code>This function's cyclomatic complexity is too high. (7)</code>. But I'm a bit confused on how I could rewrite it in such way so it works.</p>
  
  <p>This would be the function that keeps throwing that message:</p>
  
  <pre><code>function () {
    var duration = +new Date() - start.time,
      isPastHalf = Number(duration) &lt; 250 &amp;&amp; Math.abs(delta.x) &gt; 20 || Math.abs(delta.x) &gt; viewport / 2,
      direction = delta.x &lt; 0;
  
    if (!isScrolling) {
      if (isPastHalf) {
        if (direction) {
          this.close();
        } else {
          if (this.content.getBoundingClientRect().left &gt; viewport / 2 &amp;&amp; pulled === true) {
            this.close();
            return;
          }
          this.open();
        }
      } else {
        if (this.content.getBoundingClientRect().left &gt; viewport / 2) {
          if (this.isEmpty(delta) || delta.x &gt; 0) {
            this.close();
            return;
          }
          this.open();
          return;
        }
        this.close();
      }
    }
  }
  </code></pre>
  
  <p>I would like to hear some advice on how I could structure my code in such way so I avoid this kind of situations.</p>