function linkRanges(inputs) {
const {min, max} = Math;
const clamp = (a, b, v) => v < a ? a : v > b ? b : v;
inputs.forEach((view, i, views) => {
view.addEventListener("input", () => {
let [a, b] = view.value;
const p = views[i - 1];
const n = views[i + 1];
const lo = p?.value[0] ?? -Infinity;
const hi = n?.value[1] ?? Infinity;
a = clamp(lo, hi, a);
b = clamp(lo, hi, b);
if(p) p.value = [lo, max(lo, a)];
if(n) n.value = [min(b, hi), hi];
view.value = [a, b];
});
});
return inputs;
}