Published
Edited
Sep 23, 2019
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
CompressInterval = (intervals) => {
const output = [];
// Set previous interval to first
let prev = [...intervals[0]];
for (let i = 1; i < intervals.length; i++) {
const cur = [...intervals[i]];
if(cur[0] < prev[1]) { // If inside
if(cur[1] > prev[1]) prev[1] = cur[1]; // Consume
} else { // New interval
output.push(prev);
prev = cur;
}
}
// Push last
output.push(prev);
return output;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more