Я хочу, чтобы моя функция вычисляла среднее значение моего массива типа Double. Массив называется "голоса". На данный момент у меня есть 10 номеров.
Когда я вызываю average function
чтобы получить среднее значение голосов массива, она не работает.
Вот мой код:
var votes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
func average(nums: Double...) -> Double {
var total = 0.0
for vote in votes {
total += vote
}
let votesTotal = Double(votes.count)
var average = total/votesTotal
return average
}
average[votes]
Как я могу назвать среднее здесь, чтобы получить среднее?