Cваял версию 2
var arr = [],
arrLng = 6000,
out=[];
for (var i = 0; i < arrLng; i++) {
arr.push(parseInt(Math.random()*arrLng))
}
//====== Deff =========
var st = +new Date(),
bound = ',';
out=[];
var tststr = bound + arr.join(bound) + bound;
for (var i = 0; i < arr.length; i++) {
var t = bound +arr[i] + bound;
if(tststr.indexOf(t)==tststr.lastIndexOf(t))out.push(arr[i])
}
var work = +new Date()-st;
alert('Deff ='+work+'\n\n'+out)
//====== Deff v2 =========
var st = +new Date(),
obj ={};
out=[];
for (var i = 0; i < arr.length; i++) {
if(obj[arr[i]]){obj[arr[i]]='D'} //Дубль
else obj[arr[i]] = i;
}
for (var key in obj) {
if(obj[key]!='D') out[obj[key]] = key
}
out = out.join(',').replace(/^,+/,'').replace(/,+$/,'').split(/,+/)
var work = +new Date()-st;
alert('Deff v2 ='+work+'\n\n'+out)
//===== danik ==========
var st = +new Date();
out=[];
for (var i = 0; i < arr.length; i++) {
var item = arr[i];
if (arr.indexOf(item, i + 1) === -1 && (i === 0 || arr.lastIndexOf(item, i - 1) === -1))
out.push(item);
}
var work = +new Date()-st;
alert('danik ='+work+'\n\n'+out)
//===== рони ==========
var st = +new Date();
out=[];
arr.sort(function (a, b) {
return a - b;
});
for (var i = 0; i < arr.length; i++) {
var item = arr[i];
if (item != arr[i - 1] && arr[i + 1] != item)
out.push(item);
}
var work = +new Date()-st;
alert('рони ='+work+'\n\n'+out)