deduplication(){
let a = [1,1,2,3,5,6,4,2]
let b = new Set(a)
}
deduplication(){
let a = [1,1,2,3,5,6,4,2]
let flag = false//标志:当新数组中没有旧数组元素,设为true可插入
let b = new Array()
b.push(a[0])
for(let i = 0;ifor(let j = 0;jif(b[j] == a[i]){
flag = false
break
}
flag = true
}
if(flag == true){
b.push(a[i])
}
}
console.log(b)
},
deduplication(){
let a = [1,1,2,3,5,6,1,4,2,1]
let b = a.sort()//对a数组进行排序
let c = new Array()
c.push(b[0])
for(let i = 1 ; i < b.length ;i++){
if(b[i] != b[i-1]){
c.push(b[i-1])
}
}
console.log(c)
}
deduplication(){
let a = [1,1,2,3,5,6,1,4,2]
let map = new Map()
let arr = new Array()
for(let i = 0; iif(map[a[i]] === undefined){
map[a[i]] = i
arr.push(a[i])
}
}
return arr
},
原创©本文章为梁鹏翱原创,未经许可,禁止转载
0条评论