Or the recursive version, upon sorting:
function find_dupe(a){ if(a.length==0) return -1;
if (a[0]==a[1]) return a[0]; else return find_dupe(a.slice(1,a.length)); }
BTW, are loops more efficient than recursion in JS? It sure seems like a lot of JS libraries out there including jQuery avoid recursion like plague.