title: Find longest sequence of zeros in binary representation of an integer in JavaScript?
body: <ol>
  <li>Well in this question I have to find the longest sequence of zeros in the binary representation of an integer.</li>
  <li>After a lot of hard work, I'm able to find the longest sequence of zeros with my logic which I changed many times.</li>
  <li>I have one problem with my logic which is if I input an integer that has no gap in it has to give me an answer 0 which I tried to make by myself but I failed.</li>
  <li>Right now if I input an integer that has no gap it gives me output infinity.</li>
  <li>I want my answer to print 0 when the binary representation of an integer has no gap in it.</li>
  </ol>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var dn = prompt("Enter a number: ");
  var bn = new Array();
  var i = 0;
  var binary = [];
  
  while (dn != 0) {
    bn[i] = dn % 2;
    dn = Math.floor(dn / 2);
    i++;
  }
  
  for (var j = i - 1; j &gt;= 0; j--) {
    binary.push(bn[j]);
  }
  console.log(binary.join(""));
  
  var currentGap = 0;
  var gaps = [];
  var len = binary.length;
  
  for (var k = 0; k &lt; len; k++) {
    if (binary[k] == 0) {
      currentGap++;
      if (binary[k + 1] == 1) {
        gaps.push(currentGap);
        currentGap = 0;
      }
    }
  }
  
  console.log(Math.max(...gaps));</code></pre>
  </div>
  </div>
  </p>