title: Arrays - Find missing numbers in a Sequence
body: <p>I'm trying to find an easy way to loop (iterate) over an array to find all the missing numbers in a sequence, the array will look a bit like the one below.</p>
  
  <p><code>var numArray = [0189459, 0189460, 0189461, 0189463, 0189465];</code></p>
  
  <p>For the array above I would need <code>0189462</code> and <code>0189464</code> logged out.</p>
  
  <p><strong>UPDATE</strong> : this is the exact solution I used from Soufiane's answer.</p>
  
  <pre><code>var numArray = [0189459, 0189460, 0189461, 0189463, 0189465];
  var mia= [];
  
      for(var i = 1; i &lt; numArray.length; i++) 
      {     
          if(numArray[i] - numArray[i-1] != 1) 
          {         
              var x = numArray[i] - numArray[i-1];
              var j = 1;
              while (j&lt;x)
              {
                  mia.push(numArray[i-1]+j);
                  j++;
              }
          }
      }
  alert(mia) // returns [0189462, 0189464]
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Here's a neater version using .reduce</p>
  
  <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 numArray = [0189459, 0189460, 0189461, 0189463, 0189466];
  var mia = numArray.reduce(function(acc, cur, ind, arr) {
    var diff = cur - arr[ind-1];
    if (diff &gt; 1) {
      var i = 1;
      while (i &lt; diff) {
        acc.push(arr[ind-1]+i);
        i++;
      }
    }
    return acc;
  }, []);
  console.log(mia);</code></pre>
  </div>
  </div>
  </p>