Public
Edited
Dec 6, 2022
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
pairSections = input
.trim()
.split("\n")
.map(pair => pair
.split(",")
.map(bounds => bounds
.split("-")
.map(n => Number(n))));
// DON'T FORGET TO CONVERT STRING REPRESENTATIONS OF NUMBERS INTO NUMBERS!
Insert cell
function checkFullContainment([[lower1, upper1], [lower2, upper2]]) {
// Check for pair 1 inside of pair 2
if (lower1 >= lower2 && upper1 <= upper2) return 1;
// Check for pair 2 inside of pair 1
if (lower2 >= lower1 && upper2 <= upper1) return 1;

return 0;
}
Insert cell
fullContainmentCount = pairSections
.map(checkFullContainment)
.reduce((total, value) => total + value);
Insert cell
Insert cell
function checkOverlap([[lower1, upper1], [lower2, upper2]]) {
if (upper1 >= lower2 && upper2 >= lower1) return 1;
return 0;
}
Insert cell
overlapCount = pairSections
.map(checkOverlap)
.reduce((total, value) => total + value);
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