I was trying to make a clone of multidimensional slice, because when I have changed elements in the duplicated slice, the elements in the original one were overwritten also.
The only method that worked for me was:
duplicate := make([][]int, len(matrix))
for i := 0; i < len(matrix); i++ {
duplicate[i] = make([]int, len(matrix[0]))
for j := 0; j < len(matrix[0]); j++ {
duplicate[i][j] = matrix[i][j]
}
}
is there any other way - shorter or more efficient to achieve the same result? thanks