-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
_content: change generic min example to index
This avoids importing the constraints package, which is no longer in the standard library. For golang/go#50792 Change-Id: I0e0f48d414e87418a1fe95e500bb7629127007cc Reviewed-on: https://go-review.googlesource.com/c/website/+/383254 Reviewed-by: Eli Bendersky <[email protected]> Reviewed-by: Eli Bendersky <[email protected]> Trust: DO NOT USE <[email protected]> Run-TryBot: DO NOT USE <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
- Loading branch information
1 parent
b7142a0
commit 3547304
Showing
3 changed files
with
23 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// The index function returns the index of the first occurrence of v in s, | ||
// or -1 if not present. | ||
func index[E comparable](s []E, v E) int { | ||
for i, vs := range s { | ||
if v == vs { | ||
return i | ||
} | ||
} | ||
return -1 | ||
} | ||
|
||
func main() { | ||
s := []int{1, 3, 5, 2, 4} | ||
fmt.Println(index(s, 3)) | ||
fmt.Println(index(s, 6)) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters