找出预分配切片里的 bug

来自 切片
Go 1.27 入门 4分钟 找出 1处问题

找出 collect 为什么会返回输入两倍数量的元素。

Go
func collect(ids []int) []int {
    result := make([]int, len(ids))
    for _, id := range ids {
        result = append(result, id)
    }
    return result
}
在试验场中打开
报告错误