go_slice

package module
v0.0.0-...-0860709 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: BSD-2-Clause Imports: 3 Imported by: 0

README

go_slice

-- a package to work with arrays in golang

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendSlices

func AppendSlices(first, second []string) []string

AppendSlices appends two slices

func Reverse

func Reverse[T any](in []T) []T

Reverse reverses a slice with any type

func ReverseString

func ReverseString(in []string) []string

ReverseString gets an array of strings and reverses its elements

func SortAsc

func SortAsc(slice []int)

Sorts a slice of integers in ascending order

func SortDesc

func SortDesc(slice []int)

Sorts a slice of integers in descending order

func ToInt64

func ToInt64(in []int) []int64

func TypeOf

func TypeOf[T any](in []T) string

Types

type ElementExist

type ElementExist struct {
	Exist bool
	Index int
}

type IntSlice

type IntSlice []int

digit slices

func NewIntSlice

func NewIntSlice(in []int) IntSlice

func (IntSlice) Average

func (is IntSlice) Average() float64

Average comes on a slice in int type and calculates the average of elements

func (IntSlice) SumInt

func (is IntSlice) SumInt() int64

SumInt gets a slice in type int and returns a summerize of all elements in int64

type StringArray

type StringArray []string

func NewStringArray

func NewStringArray(in []string) StringArray

NewStringArray converts an array of strings to a StringArray

func (StringArray) AppendElementToTheEnd

func (sa StringArray) AppendElementToTheEnd(element string) []string

AppendElementToTheEnd appends an element to the end of an string arrey

func (StringArray) AppendElementToTheFirst

func (sa StringArray) AppendElementToTheFirst(element string) []string

AppendElementToTheFirst appends an element to the very first of an string arrey

func (StringArray) AttachElements

func (sa StringArray) AttachElements() string

AttachElements concatenates the elements of a StringArray into a single string

func (StringArray) AttachElementsBySpace

func (sa StringArray) AttachElementsBySpace() string

AttachElementsBySpace concatenates the elements of a StringArray into a single string separated by spaces

func (StringArray) CountElements

func (sa StringArray) CountElements() int

CountElements returns the number of elements in a StringArray

func (StringArray) DeleteElement

func (sa StringArray) DeleteElement(element string) []string

TODO: complete this ...

func (StringArray) ElementExist

func (sa StringArray) ElementExist(element string) ElementExist

ElementExist checks if an element exists in a StringArray and returns its index

func (StringArray) ElementsIndexMapper

func (sa StringArray) ElementsIndexMapper() map[int]string

ElementsIndexMapper maps arrays element to its index

func (StringArray) ReverseRange

func (sa StringArray) ReverseRange(i int) (int, string)

ReverseRange iterates on the string array backwardly

sample usage :

arr := []string{"one","two","three"} index := 0 for (

if index == len(arr) {
	break()
}
i,v := arr.ReverseRange(index)
index ++

)

func (StringArray) ShiftElements

func (sa StringArray) ShiftElements(n int) []string

ShiftElements to shift to the right use minus digits and positive digits to shift to the left

func (StringArray) ToDigits

func (sa StringArray) ToDigits() []int

ToDigits converts the string elements to digits and return the corresponding int array

Jump to

Keyboard shortcuts

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