You can do like that:
let obj = [{start:1, end: 100},
{start:401, end: 500},
{start:101, end: 300}]
obj.sort(function(a, b) {
return a.start - b.start;
})
for (let i = 0; i < obj[obj.length - 1].end; i ++) {
if (i + 1 < obj.length && obj[i].end + 1 !== obj[i + 1].start) {
console.log('Discontinuity: ', obj[i].end + 1);
}
}
//With forEach if needed
obj.forEach( (element, i) => {
if (i + 1 < obj.length && obj[i].end + 1 !== obj[i + 1].start) {
console.log('Discontinuity: ', obj[i].end + 1);
}
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…