Guest User

Untitled

a guest
Jul 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. func unique(tokens *[]string) {
  2. v := reflect.ValueOf(tokens).Elem()
  3. if v.Len() <= 1 {
  4. return
  5. }
  6. sort.Strings(*tokens)
  7.  
  8. i := 0
  9. for j := 1; j < v.Len(); j++ {
  10. if (*tokens)[i] == (*tokens)[j] {
  11. continue
  12. }
  13. // unique token, save it
  14. i++
  15. v.Index(i).Set(v.Index(j))
  16. }
  17. i++
  18. v.SetLen(i)
  19. }
Add Comment
Please, Sign In to add comment