你应该尝试开始一些事情并自己处理这个问题。
var arr = [{ Min :0, Max:25 } , { Min:26, Max:28}, { Min:35, Max:41}, { Min:48, Max:71}];
var range = [];
for(var i = 0; i <= 100; i++)
{
range.push(true); // first set it as missing...
}
for(var i = 0 ; i < arr.length ; i++)
{
for(var j = arr[i].Min ; j <= arr[i].Max ; j++)
{
range[j] = false; // loop the array and set it to false
}
}
var missingPart = '';
var start = false;
for(var i = 0 ; i < range.length ; i++) // loop the range array and build result
{
if(range[i])
{
if(!start)
{
start = true;
if(missingPart)
{
missingPart+=", ";
}
missingPart += i;
}
}
else
{
if(start)
{
start = false;
missingPart += ("-" + (i-1));
}
}
}
if(start)
{
missingPart += ("-100");
}
document.getElementById("counter").innerHTML = missingPart
在这里找到 jsFiddle 结果:http: //jsfiddle.net/gm4HG/2/