## 去重
去掉slice中重复的数据
```
package main
import (
"fmt"
)
func main() {
orderIds := make([]int64, 0)
orderIds = []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 2, 4, 5}
// 最直接的方式
slice := make([]interface{}, len(orderIds))
for i := range orderIds {
slice[i] = orderIds[i]
}
slice = removeDuplicate(slice)
fmt.Println(slice)
}
// 去掉slice中重复的元素
func removeDuplicate(slice []interface{}) []interface{} {
newSlice := make([]interface{}, 0, len(slice))
for _, old := range slice {
isExist := false
for _, new := range newSlice {
if new == old {
isExist = true
break
}
}
if !isExist {
newSlice = append(newSlice, old)
}
}
return newSlice
}
```
by zzj
有疑问加站长微信联系(非本文作者))