]> Cypherpunks repositories - gostls13.git/commitdiff
sort: fix search descending order example
authorSuyash <dextrous93@gmail.com>
Fri, 16 Sep 2016 14:24:44 +0000 (19:54 +0530)
committerJoe Tsai <thebrokentoaster@gmail.com>
Sat, 17 Sep 2016 00:14:19 +0000 (00:14 +0000)
Change-Id: I27b82d8c63a06ddf7e148b15853aba24a22a6282
Reviewed-on: https://go-review.googlesource.com/29336
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/sort/example_search_test.go

index 345590cb4dd2905fa09bfebf85cd2a73f6de4a53..6928f0f092db415f260e6590404a82f1e8313f4e 100644 (file)
@@ -32,7 +32,7 @@ func ExampleSearch_descendingOrder() {
        x := 6
 
        i := sort.Search(len(a), func(i int) bool { return a[i] <= x })
-       if a[i] == x {
+       if i < len(a) && a[i] == x {
                fmt.Printf("found %d at index %d in %v\n", x, i, a)
        } else {
                fmt.Printf("%d not found in %v\n", x, a)