In Golang, I am trying to sort a slice without mutating the original value
func main() {
originalArray := []int{4, 2, 1, 1, 2}
newArray := originalArray
sort.Ints(newArray)
fmt.Printf("%v", originalArray) // prints [1 1 2 2 4]
}
How can I sort a slice in golang
without mutating the original value?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…