slice

package
v1.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareStringSlice

func CompareStringSlice(s1, s2 []string) bool

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

func CountDuplicateEntries(list []string) map[string]int

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

func DuplicateEntryExists(stringSlice []string) bool

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

func EntryExists(slice []string, entry string) bool

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

func GetSliceEntryIndex(slice []string, entry string) int

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

func RemoveDuplicateEntries(stringSlice []string) []string

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

func RemoveEntryFromSlice(slice []string, entry string) []string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL