function compare(l, r) {
if (typeof l === "number" && typeof r === "number") {
if (l < r) return -1;
if (l > r) return 1;
} else if (typeof l === "object" && typeof r === "object") {
for (const [left, right] of d3.zip(l, r)) {
const c = compare(left, right);
if (c) return c;
}
if (l.length < r.length) return -1;
if (l.length > r.length) return 1;
} else if (typeof l === "number") {
return compare([l], r);
} else {
return compare(l, [r]);
}
return 0;
}