* last function

* drop function

* add documentation

* fix CI

Co-authored-by: Ruidy <rnemausat@newstore.com>
This commit is contained in:
Ruidy 2022-03-21 13:04:38 -04:00 committed by GitHub
parent fb517f3b04
commit c00d9af59f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

12
drop.go Normal file
View file

@ -0,0 +1,12 @@
package underscore
// Drop returns the rest of the elements in a slice.
// Pass an index to return the values of the slice from that index onward.
func Drop[T any](values []T, index int) (rest []T) {
for i, value := range values {
if i != index {
rest = append(rest, value)
}
}
return rest
}

17
drop_test.go Normal file
View file

@ -0,0 +1,17 @@
package underscore_test
import (
"testing"
"github.com/stretchr/testify/assert"
u "github.com/rjNemo/underscore"
)
func TestDrop(t *testing.T) {
nums := []int{1, 9, 2, 8, 3, 7, 4, 6, 5}
want := []int{1, 9, 2, 3, 7, 4, 6, 5}
assert.Equal(t, want, u.Drop(nums, 3))
}