Skip to content

Commit

Permalink
Merge pull request #4 from ric-v/dev
Browse files Browse the repository at this point in the history
added remove elem and removeat
  • Loading branch information
ric-v authored Mar 19, 2022
2 parents 4248137 + 9c4feec commit 3ed5208
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 3ed5208

Please sign in to comment.