Spot the ordering bug when using a hash set to detect duplicate values in an array.
Codejavascript
function hasDuplicate(arr) {
const seen = new Set();
for (const num of arr) {
seen.add(num);
if (seen.has(num)) {
return true;
}
}
return false;
}
console.log(hasDuplicate([1, 2, 3])); // expected false