Public
Edited
Dec 5, 2022
Insert cell
Insert cell
Insert cell
{
let fulloverlaps = 0;
for (const pair of cleaning) {
if (pair.length < 2) continue;
const r1 = pair[0].split("-").map((n) => +n);
const r2 = pair[1].split("-").map((n) => +n);
if (fullycontains(r1, r2) || fullycontains(r2, r1)) fulloverlaps++;
}
return fulloverlaps;
}
Insert cell
function fullycontains(first, second) {
return first[0] >= second[0] && first[1] <= second[1];
}
Insert cell
Insert cell
{
let count = 0;
for (const pair of cleaning) {
if (pair.length < 2) continue;
const r1 = pair[0].split("-").map((n) => +n);
const r2 = pair[1].split("-").map((n) => +n);
if (overlaps(r1, r2) || overlaps(r2, r1)) count++;
}
return count;
}
Insert cell
function overlaps(first, second) {
return contains(first[0], second) || contains(first[1], second);
}
Insert cell
function contains(number, range) {
return number >= range[0] && number <= range[1];
}
Insert cell
Insert cell
cleaning = rawData.split("\n").map((p) => p.split(","))
Insert cell
rawData = FileAttachment("cleaning.txt").text()
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