Skip to content

Commit

Permalink
added remove elem and removeat
Browse files Browse the repository at this point in the history
  • Loading branch information
ric-v committed Mar 19, 2022
1 parent e2eee13 commit 9c4feec
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions array/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func Filter[T arrTypes](a []T, f func(T) bool) []T {
return b
}

// RemoveAt removes the first element in the array that equals the searchKey.
func RemoveAt[T arrTypes](a []T, searchKey T) []T {
// RemoveElem removes the first element in the array that equals the searchKey.
func RemoveElem[T arrTypes](a []T, searchKey T) []T {
_, i, _ := in(a, searchKey)
// check if i is out of bounds
if i+1 > len(a) {
Expand All @@ -64,6 +64,14 @@ func RemoveAt[T arrTypes](a []T, searchKey T) []T {
return append(a[:i], a[i+1:]...)
}

// RemoveAt removes the element at the index i.
func RemoveAt[T arrTypes](a []T, i int) []T {
if i+1 > len(a) {
return a[:i]
}
return append(a[:i], a[i+1:]...)
}

// InsertAt inserts the newValue at the index i.
func InsertAt[T arrTypes](a []T, i int, v T) []T {
// check if i is out of bounds
Expand Down

0 comments on commit 9c4feec

Please sign in to comment.