how to return first duplicate in array js 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
}