Skip to content

Commit ce0db07

Browse files
committed
Add contains function
1 parent 2a406c5 commit ce0db07

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ds/minislice.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ func (s *MiniSlice[A, T]) Append(val T) {
5656
s.nextArrayIdx++
5757
}
5858

59+
// Returns true if the slice has the requested value
60+
func (s *MiniSlice[A, T]) Contains(searchVal T) bool {
61+
// Logic: If we return a positive value, then we must have found it
62+
return (s.Find(searchVal) >= 0)
63+
}
64+
5965
// Find and return the index of the first element, else return -1
6066
func (s *MiniSlice[A, T]) Find(searchVal T) int {
6167
for i, val := range s.All() {

0 commit comments

Comments
 (0)