Standard library / sort

sort.SearchInts()

Returns the first index at which the target can be inserted in an ascending sorted slice. Check equality separately for membership. Expected stdout: '1 3\n'.

Formal Syntax & Structure

go syntaxgo
func SearchInts(a []int, x int) int

Parameters & Attributes

NameTypeDescription
a[]intSorted input slice.
xintInput value or collection to process.

Return Value

int

Returns the first index at which the target can be inserted in an ascending sorted slice. Check equality separately for membership.

Working Example

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