How do I partition a slice of ints in Go?

In Go, partitioning a slice of integers involves rearranging the elements into two groups based on a pivot value, with one group containing elements less than or equal to the pivot, and the other containing elements greater than the pivot. Here's how to do it:

func partition(slice []int, pivot int) ([]int, []int) { var less []int var greater []int for _, value := range slice { if value <= pivot { less = append(less, value) } else { greater = append(greater, value) } } return less, greater } func main() { nums := []int{8, 3, 5, 2, 10, 6} pivot := 5 less, greater := partition(nums, pivot) fmt.Println("Less than or equal to pivot:", less) fmt.Println("Greater than pivot:", greater) }

Go partition slice integers programming coding Golang