function intersection(listA, listB) {
if (listA == null) throw `listA not defined`;
if (listB == null) throw `listB not defined`;
const n = listA.length;
const m = listB.length;
listA.sort(d3.ascending);
listB.sort(d3.ascending);
const result = [];
let i = 0;
let j = 0;
while (i < n && j < m) {
if (listA[i] < listB[j]) {
for (const ai = listA[i++]; i < n && ai == listA[i]; i++);
} else if (listA[i] > listB[j]) {
for (const bj = listB[j++]; j < m && bj == listB[j]; j++);
} else {
result.push(listA[i]);
for (const ai = listA[i++]; i < n && ai == listA[i]; i++);
for (const bj = listB[j++]; j < m && bj == listB[j]; j++);
}
}
return result;
}