title: Validate number of days in a given month
body: <p>Performance is of the utmost importance on this one guys... This thing needs to be lightning fast!
  <br />
  <br />
  <br />
  How would you validate the number of days in a given month?</p>
  <p>My first thought was to make an array containing the days of a given month, with the index representing the month:</p>
  <pre><code>var daysInMonth = [
      31, // January
      28, // February
      31, // March
      etc.
  ];
  </code></pre>
  <p>And then do something along the lines of:</p>
  <pre><code>function validateDaysInMonth(days, month)
  {
      if (days &lt; 1 || days &gt; daysInMonth[month]) throw new Error(&quot;Frack!&quot;);
  }
  </code></pre>
  <p>But... What about leap years? How can I implement checking for leap years and keep the function running relatively fast?
  <br />
  <br />
  <br />
  <strong>Update:</strong> I'd like you guys to show me some code which does the days in month- leap year validation.</p>
  <p>Here's the flowchart describing the logic used today:</p>
  <p><a href="https://i.stack.imgur.com/wlSWs.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wlSWs.gif" alt="" /></a><br />
  <sub>(source: <a href="http://visualbasic.about.com/library/graphics/dykleapyr1-1.gif" rel="nofollow noreferrer">about.com</a>)</sub></p>