var ary=[1,0,2,1,2,3,5,5,3,3,3,4,2,1,1,1,2,4,5,3,0,0,2,1,0];
function fn(arr) {
for(var i=0;i<arr.length-1;i++){
for(var j=i+1;j<arr.length;j++){
if(arr[j]==arr[i]){
arr.splice(j,1);
j--;
}
}
}
return arr;
}
console.log(fn(ary));
var ary=[1,0,2,1,2,3,5,5,3,3,3,4,2,1,1,1,2,4,5,3,0,0,2,1,0];
function fn(arr) {
var obj={};
for (var i=0;i<arr.length;i++){
var cur=arr[i];
if (obj[cur]){
arr.splice(i,1);
i--;
}else {
obj[cur]="已存";
}
}
obj=null;
return arr;
}
console.log(fn(ary));
var ary=[1,0,2,1,2,3,5,5,3,3,3,4,2,1,1,1,2,4,5,3,0,0,2,1,0];
function fn(arr) {
var obj={};
for(var i=0;i<arr.length;i++){
var cur=arr[i];
if(obj[cur]){
ary.splice(i,1);
obj[cur]++;
i--;
}else {
obj[cur]=1;
}
}
console.log(obj);
return arr;
}
console.log(fn(ary));
var ary=[1,0,2,1,2,3,5,5,3,3,3,4,2,1,1,1,2,4,5,3,0,0,2,1,0];
function fn(arr) {
var ary=[];
for (var i=0;i<arr.length;i++){
if(ary.indexOf(arr[i])==-1){
ary.push(arr[i]);
}
}
return ary;
}
console.log(fn(ary));