Documentation ¶
Index ¶
- func CompareStringSlice(s1, s2 []string) bool
- func CountDuplicateEntries(list []string) map[string]int
- func DuplicateEntryExists(stringSlice []string) bool
- func EntryExists(slice []string, entry string) bool
- func GetSliceEntryIndex(slice []string, entry string) int
- func RemoveDuplicateEntries(stringSlice []string) []string
- func RemoveEntryFromSlice(slice []string, entry string) []string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareStringSlice ¶
CompareStringSlice compares two slices of strings. The function returns a boolean response
true : the slices match func : the slices do not match
Example ¶
slice1 := []string{"one", "two", "three"} slice2 := []string{"two", "one", "three"} fmt.Println(CompareStringSlice(slice1, slice2))
Output: true
func CountDuplicateEntries ¶
CountDuplicateEntries counts the number of times a entry repeats in a slice of strings The function returns a map with the unique entries in the slice as keys and the duplicate frequencies of the unique entries of the slice
Example ¶
slice := []string{"one", "two", "two", "three", "three", "three"} fmt.Println(CountDuplicateEntries(slice))
Output: map[one:1 three:3 two:2]
func DuplicateEntryExists ¶
DuplicateEntryExists checks if a slice has duplicate entries or not The function returns a boolean response
true : the slice contains duplicate entries func : the slice does not contain duplicate entries
Example ¶
slice := []string{"one", "two", "two"} fmt.Println(DuplicateEntryExists(slice))
Output: true
func EntryExists ¶
EntryExists checks if an entry exists in a slice of strings The function returns a boolean value:
true if the entry exists or false if the entry does not exist
Example ¶
slice := []string{"one", "two", "three"} fmt.Println(EntryExists(slice, "two"))
Output: true
func GetSliceEntryIndex ¶
GetSliceEntryIndex returns the index of an entry in a slice of strings The function returns an integer value of the index of the first occurrence of the slice entry
Example ¶
slice := []string{"one", "two", "three"} fmt.Println(GetSliceEntryIndex(slice, "one"))
Output: 0
func RemoveDuplicateEntries ¶
RemoveDuplicateEntries removes duplicate entries in a slice of strings The function returns a slice with unique string entries
Example ¶
slice := []string{"one", "two", "two", "three", "three", "three", "four", "four", "four", "four"} fmt.Println(RemoveDuplicateEntries(slice))
Output: [one two three four]
func RemoveEntryFromSlice ¶
RemoveEntryFromSlice removes a entry from a slice of strings The function removed the first occurrence of the entry and then returns the updated slice back If the Entry does not exist then the function returns the same slice back
Example ¶
slice := []string{"one", "two", "three"} fmt.Println(RemoveEntryFromSlice(slice, "two"))
Output: [one three]
Types ¶
This section is empty.