Find why this generated cycle detector reports a shared child as a cycle.
JavaScript
function containsCycle(root) {
const seen = new WeakSet();
function visit(value) {
if (value === null || typeof value !== 'object') return false;
if (seen.has(value)) return true;
seen.add(value);
return Object.values(value).some(visit);
}
return visit(root);
}
const address = { country: 'FR' };
const order = { billing: address, shipping: address };
console.log(containsCycle(order));