So I'm trying to compile the forllowing code in go, which I just picked up a few hours ago
package main
import "fmt"
func main() {
a := [...]float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
sum := avg(a)
fmt.Println(sum)
}
func avg(arr []float64) (sum float64) {
for _, v := range arr {
sum += v
}
sum = sum / float64(len(arr))
return
}
I get an error saying that I can't pass the 10 element long array because the function was defined with a []float64 array. Is there a way around this or am I missing something obvious?