Standard library / sort

sort.IntSlice.Search()

Returns lower-bound insertion index in an ascending sorted receiver. Does not sort the receiver first or return a found flag. Expected stdout: '1 3\n'.

Formal Syntax & Structure

go syntaxgo
func (p IntSlice) Search(x int) int

Parameters & Attributes

NameTypeDescription
xintInput value or collection to process.

Return Value

int

Returns lower-bound insertion index in an ascending sorted receiver. Does not sort the receiver first or return a found flag.

Working Example

Example Snippetgo
package main
import (  "fmt"  "sort")
func main() {  a := sort.IntSlice([]int{1, 2, 3})  fmt.Println(a.Search(2), a.Search(4))}
Go Reference