//sample solution
function makeArrayConsecutive2(sequence) {
sequence.sort(function(a,b){return a - b}) //for correct number sorting
//document.writeln("sorted: ", sequence, "<br/>");
var lowestElement = sequence[0];
var highestElement = sequence[sequence.length-1];
var properSequence = [];
if(highestElement - lowestElement >= 0){
for(i=lowestElement; i<=highestElement; i++){
properSequence.push(i);
}
} else {
for(i=lowestElement; i>=highestElement; i--){
properSequence.push(i);
}
}
//document.writeln("proper: ", properSequence, "<br/>");
var numberOfHoles = properSequence.length - sequence.length;
return numberOfHoles;
}
No comments:
Post a Comment