Uniqify

    Go

    1. package main
    2.  
    3. import "fmt"
    4.  
    5. func uniqify(items *[]string) {
    6. j := 0
    7. for i, x := range *items {
    8. if !seen[x] {
    9. seen[x] = true
    10. (*items)[j] = (*items)[i]
    11. j++
    12. }
    13. *items = (*items)[:j]
    14. }
    15.  
    16. func main() {
    17. items := []string{"B", "B", "E", "Q", "Q", "Q"}
    18. uniqify(&items)
    19. fmt.Println(items) // prints [B E Q]