Is there anyway to sort a slice and assign it to another variable? I noticed that the method sort.Ints()
mutates the original slice.
func main() {
xi := []int{4, 7, 3, 42, 99, 18, 16, 56, 12}
fmt.Println(xi)
sort.Ints(xi)
fmt.Println(xi)
}
I tried using these:
newXi := sort.Ints(xi)
var newXi1 int[]
newXi1 = sort.Ints(xi)
var newXi2 int[]
append(newXi2, sort.Ints(xi))
but none of them work. Any tips?