find the first duplicate in an array javascript code example
Example: first duplicate javascript
function firstDuplicate(a) {
let data = [];
for (dup of a) {
if (data[dup]) {
return dup
} else {
data[dup] = dup
}
}
return -1
}