slice.go 595 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package stringy
  2. func Add(s []string, a string) []string {
  3. for _, existing := range s {
  4. if a == existing {
  5. return s
  6. }
  7. }
  8. return append(s, a)
  9. }
  10. func Union(s []string, a []string) []string {
  11. for _, entry := range a {
  12. found := false
  13. for _, existing := range s {
  14. if entry == existing {
  15. found = true
  16. break
  17. }
  18. }
  19. if !found {
  20. s = append(s, entry)
  21. }
  22. }
  23. return s
  24. }
  25. func Uniq(s []string) (r []string) {
  26. outerLoop:
  27. for _, entry := range s {
  28. for _, existing := range r {
  29. if existing == entry {
  30. continue outerLoop
  31. }
  32. }
  33. r = append(r, entry)
  34. }
  35. return
  36. }