Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

first duplicate javascript

function firstDuplicate(a) {
    let data = [];
    
    for (dup of a) {
        if (data[dup]) {
            return dup
        } else {
            data[dup] = dup
        }
    }
    return -1
}
 
PREVIOUS NEXT
Tagged: #duplicate #javascript
ADD COMMENT
Topic
Name
8+1 =