# In a cyclical array, find the missing number

Using Javascript or jQuery, I need to compare two arrays and discover the missing integer. Finding all missing numbers is simple, however, I must interpret the first array as if it were cyclical in order to discover only the one missing number between the provided numbers in the second array.

``````var numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13]
var unsorted = [13,12,1,3]
``````

How can I compare the two arrays and get the missing number 2 while still returning the numbers 4-11 as explained in this example?
It’s conceivable that comparing two arrays is the incorrect approach. My current code is as follows:

``````// Function: Put numbers in order and return the missing number from the 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 < 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.)
``````

Any assistance is much appreciated. Thank you very much!