diff --git a/drop.go b/drop.go new file mode 100644 index 0000000..e572c74 --- /dev/null +++ b/drop.go @@ -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 +} diff --git a/drop_test.go b/drop_test.go new file mode 100644 index 0000000..97a187d --- /dev/null +++ b/drop_test.go @@ -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)) +}