<html>
<head>
<script language="javascript" type="text/javascript">
function findMissingNumbersInArray(sequenceA, sequenceB) {
var missingSequenceOfNumbers = [];
/* Sort the sequences passed to this function */
sequenceA.sort(function(a, b) {return a - b});
sequenceB.sort(function(a, b) {return a - b});
/* Iterate through the base array containing the complete sequence */
for (var b = 0; b < sequenceA.length; b++) {
var baseValue = sequenceA[b];
if (baseValue <= sequenceB[(sequenceB.length - 1)]) {
/* Iterate through the array containing the fragmented sequence */
var baseValueFound = false;
for (var f = 0; f < sequenceB.length; f++) {
var fragmentValue = sequenceB[f];
if (baseValue == fragmentValue) {
baseValueFound = true;
}
}
/* Save the missing number in the fragmented sequence */
if (baseValueFound == false) {
missingSequenceOfNumbers.push(baseValue);
}
}
}
return(missingSequenceOfNumbers);
}
</script>
</head>
<body onload='javascript:document.getElementById("output").value = findMissingNumbersInArray([1,2,3,4,5,6], [2,3,1,0,5]);'>
Given a base array sequence: [1,2,3,4,5,6]<br />
find the missing numbers in the fragmented array sequence: [2,3,1,0,5]<br />
that are present in the base array but do not exceed the highest value in the fragmented array sequence.<br />
<span style="font-size:9pt">For reference, the missing numbers returned should be: [4]</span>
<br /><br />
<strong>Function Logic Output:</strong><br />
<textarea name="output" id="output" rows="4" cols="30"></textarea>
</body>
</html>