Documentation
¶
Overview ¶
Package arr contains functions to interact with arrays.
The package is imported like this:
import "github.com/gouniverse/base/arr"
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterEmpty ¶ added in v0.1.0
FilterEmpty takes a slice of strings and returns a new slice with all empty strings removed.
Example:
arr.FilterEmpty([]string{"", "hello", "", "world"}) // returns []string{"hello", "world"}
Parameters: - slice: the slice of strings to filter.
Returns: - []string: a new slice with all empty strings removed.
func IndexMoveDown ¶
indexMoveDown moves the element at the given index down
Business logic: - if the index is last index, will be ignored - if the index out of bounds, will be ignored
Parameters: - slice: the slice to move the element from - index: the index of the element to move
Returns: - []T: the new slice
Example:
arr := []int{1, 2, 3, 4}
result := IndexMoveDown(arr, 1)
// result is now [1, 4, 2, 3]
func IndexMoveUp ¶
indexMoveUp moves the element at the given index up
Business logic: - if the index is first index, will be ignored - if the index out of bounds, will be ignored
Parameters: - slice: the slice to move the element from - index: the index of the element to move
Returns: - []T: the new slice
Example:
indices := []int{1, 2, 3, 4, 5}
IndexMoveUp(indices, 2)
fmt.Println(indices) // [1, 3, 2, 4, 5]
func IndexRemove ¶
IndexRemove removes the element at the given index from the slice.
Parameters: - slice: the slice to remove the element from. - index: the index of the element to remove.
Returns: - []T: a new slice with the element at the given index removed.
Business Logic: - If the index is out of bounds, the original slice is returned unchanged. - This function does not panic on an out-of-bounds index.
Example:
arr := []int{1, 2, 3, 4}
result := IndexRemove(arr, 2)
// result is now [1, 2, 4]
Types ¶
This section is empty.