title: Find missing number in cyclical array
body: <p>I have two arrays that I need to compare and find the missing number using Javascript or jQuery. Finding <em>all</em> missing numbers is relatively easy but I need to treat the first array as if it were cyclical so that I only find the single missing number between the given numbers in the second array.</p>
  
  <pre><code>var numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13]
  var unsorted = [13,12,1,3]
  </code></pre>
  
  <p>How can I compare the two arrays and return the missing number 2, <em>without also returning 4-11</em>?</p>
  
  <p>Any help is appreciated. Thank you!</p>
  
  <p><strong>Edit with more information.</strong> It's possible that comparing two arrays is the wrong way to do this. Here is my current code:</p>
  
  <pre><code>// Function: Put numbers in order and return missing number from sequence
  // Possible numbers are 1 through 13 max
  
  var cyclical = [13,12,1,3] 
  // Other examples, always only four numbers: [13,12,11,2] 1 is missing, [11,12,2,13] 1 is missing
  
  var nonCyclical = [3,1,5,4]
  // Another example: [7,3,5,4] 6 is missing
  
  function absent(arr) {
      var mia = [],
          min = Math.min.apply('', arr),
          max = Math.max.apply('', arr);
      while (min &lt; max) {
          if (arr.indexOf(++min) == -1) mia.push(min);
      }
      return mia;
  }
  
  var missingNumCyclical = absent(cyclical);
  // Result: 2,4,5,6,7,8,9,10,11
  
  var missingNum = absent(nonCyclical);
  // Result: 2 (This is the desired result.)
  </code></pre>