You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

slices.go 789B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package main
  2. import "sort"
  3. func convert2DsliceTo1D(sliceTwoDim [][]string) []string {
  4. var returnSlice []string
  5. for _, element := range sliceTwoDim {
  6. returnSlice = append(returnSlice, element[1]) // ignore
  7. }
  8. return returnSlice
  9. }
  10. func removeDuplicatesUnordered(elements []string) []string {
  11. encountered := map[string]bool{}
  12. // Create a map of all unique elements.
  13. for v := range elements {
  14. encountered[elements[v]] = true
  15. }
  16. // Place all keys from the map into a slice.
  17. result := []string{}
  18. for key := range encountered {
  19. result = append(result, key)
  20. }
  21. return result
  22. }
  23. func equalStringSlice(a, b []string) bool {
  24. if len(a) != len(b) {
  25. return false
  26. }
  27. sort.Strings(a)
  28. sort.Strings(b)
  29. for i, v := range a {
  30. if v != b[i] {
  31. return false
  32. }
  33. }
  34. return true
  35. }