Spot the bug in the preallocated slice

from Slices
Go 1.27 beginner 4 min 1 issue to find

Find why collect returns twice as many elements as its input.

Go
func collect(ids []int) []int {
    result := make([]int, len(ids))
    for _, id := range ids {
        result = append(result, id)
    }
    return result
}
Open in playground
Report an error