How to Remove duplicate values from Slice?

package main
import (
"fmt"
)
func unique(intSlice []int) []int {
    keys := make(map[int]bool)
    list := []int{}	
    for _, entry := range intSlice {
        if _, value := keys[entry]; !value {
            keys[entry] = true
            list = append(list, entry)
        }
    }    
    return list
}
func main() {
    intSlice := []int{1,5,3,6,9,9,4,2,3,1,5}
	fmt.Println(intSlice) 
    uniqueSlice := unique(intSlice)
    fmt.Println(uniqueSlice)
}
C:\golang\codes>go run example.go
[1 5 3 6 9 9 4 2 3 1 5]
[1 5 3 6 9 4 2]

C:\golang\codes>

Thanks for reading. Please leave your valuable feedback and comments.

* Required Fields

No questions yet. Be the first to ask the question!