// 第一種:
function remove(arr){
return [...new Set(arr)]
}
console.log(remove([1,2,3,4,5,5,5,5]));ide
// 第二種 O(2n)
function removeColone(arr){
let final = [];
for(let i = 0 ;i<arr.length;i++){
if(arr[i] !==arr[i+1]){
final.push(arr[i]);
}
}
console.log(final)
}
removeColone([1,2,2,3,3,4,4,5,5,5,5,7,8,9,9])code
// 第三種
function rmoveProtype(arr){
let tem ={};
for(let i = 0;i<arr.length;i++){
tem[${arr[i]}
] = 'a'
}
let result=Object.keys(tem).map(res=>{
return parseInt(res)
})
return result;
}rem
//第四種includes() == -1
function removeRepeat(arr){
var tem = [];
for(let i = 0;i<arr.length;i++){
if(!arr.includes(arr[i])){
tem.push(arr[i])
}
}
console.log(tem)
} it
//第五種filter
function removeRepeat(arr){
return arr.filter((currentValue,index,arr)=>{
return arr.indexOf(currentValue) ===index
})
}
console.log(removeRepeat([1,2,2,3,3,4,5,5,5,5]))io