$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #251

Which fix removes the bug?

src := []int{1, 2, 3}
dst := make([]int, 0, len(src))
copy(dst, src)
fmt.Println(dst) // expected [1 2 3]
  1. Swap the args: copy(src, dst)
  2. Raise the cap to len(src)+1
  3. Use make([]int, len(src))
  4. Pass a pointer: copy(&dst, src)
copy moves min(len(dst), len(src)) elements and ignores capacity. dst has length 0, so nothing is copied; give it length len(src).
Play Problem Solving ▸